Reusing my old ATV as an LMS Squeezebox Server/Player

LIke many people, I have retired my old 1st Gen Apple TV, and moved on to more powerful hardware (Vero), for my high definition video needs.

That said, the ATV runs well with OSMC installed on it’s internal HDD.

One of the very nice features of the original ATV, is it’s multiple outputs for audio and video. HDMI, Component Video, Composite Video, SPDIF Digital Audio.

With the digital audio outputs in mind, I decided to repurpose my ATV as a music playback device.

Truthfully, I don’t know how long I will actually use the ATV for this purpose.
It has some serious drawbacks compared to using a combination of a Raspberry Pi / HiFiBerry or similar:

  • It uses 32 watts of power when it’s running at idle. I would pay about $2/month or $23/Year to power it 24hrs per day. (Though… It WOULD also help heat the room in winter)
  • It only has 256MB of ram.
  • There is a limited selection of music server software that you can EASILY install on it.
  • OSMC is not longer supported on the ATV1. Using “apt-get dist upgrade” would break it.

Nevertheless, I decided to give a music server setup a try.
Who knows, eventually I may buy new hardware, for a multi location speaker setup.

Considerations:

  1. We have 9000+ tracks in our music library on our 200GB iPods. The server needs to handle that many tracks, in various formats, with metadata.
    (It initially took 2.5 weeks of effort to rip all the CDs, and digitize all the vinyl records, we have ever owned. They now reside in boxes in the basement :smiley: Eventually I’d like to rip the CDs again to FLAC for original quality, instead of compressed ones)

  2. We often listen to local radio. Especially 2 University stations.

  3. Archive.org has a lot of old radio dramas from my dad’s era, which I’d love to hear.

  4. I love hearing atypical music from all over the world.

After searching the web for various options, I tried two that would fill those needs (and more)

--------------------------------------------------------------------------------------------

Mopidy

Mopidy looked like it would be great to use on the ATV1.
It was more effort to install, but MOST importantly, was unstable on the ATV1.
When I scanned my music collection, the system crashed/segfault due a lack of memory. (there are other users with a lot more ram logging the same issue on github)
Tweaking the settings allowed me to successfully scan my music files, but it would still stutter when playing some music files.
It may be possible to tweak the configuration more so that it would run ok, but I don’t have time to figure it out. (if anyone has Mopidy running well on the ATV1, please post details)

--------------------------------------------------------------------------------------------

Logitech Media Server (Squeezebox) and Squeezelite Software Client/Player

http://www.mysqueezebox.com/
http://downloads.slimdevices.com/

While Logitech Media Server (LMS) was designed for use with Logitech hardware players/clients, there is good DIY support. It supports music, video, and images.

There is a problem though…
The server software uses the website mysqueezebox.com for plugin/app installation and operation, so there is a risk that when Logitech finally closes down the weberver, Logitech Media Server (LMS) functions will stop working.

Since I want the ATV1 to output an audio signal, I installed a software based player/client called squeezelite. It can receive a stream from the server software, just like the original Logitech hardware players/clients.

Task List

  1. Remove the Crystal HD video card, and reinstall the original WiFi card.
  2. Do a fresh install of OSMC, onto the internal hard drive of the Apple TV1
  3. Install / Configure Samba to share the media directory so music can be added/deleted remotely.
  4. Install Logitech Media Server and plugins
  5. Disable Kodi from starting automatically in OSMC. (lower memory/CPU demand)

Step 1 and 2:
I won’t go into details. Any AppleTV/OSMC user has done them. Full info is on the OSMC wiki pages.

Step 3 - Install SMB/Samba:

You will want a way to remotely add/delete files from your local music library.

I wuld have preferred to use NFS, but couldn’t get it to work with the external HFS+ drive that my music library is on.
I used samba due to it’s ease of configuration, and operation with HFS+ drives

The easiest way to do this is to use the OSMC App Store in the “My OSMC” menu.

If you are running the OSMC 2017.08-1 for ATV1, the app store is not working correctly.
No problem… you can install smb via ssh/command line with:
sudo apt-get install smb-app-osmc

Read the comments in the file /etc/samba/smb.conf

Then use either smb-local.conf or smb-shares.conf to configure which directories you want to share.

Search the web for “debian smb configuration” and you will find a full docs on how to do this. including restricting access to specific users.

Step 4: Download the installer package for LMS Server 7.9:

wget http://downloads.slimdevices.com/nightly/7.9/sc/3625c6d/logitechmediaserver_7.9.1~1513951369_i386.deb

Step 5: Install the LMS server package:

sudo dpkg -i logitechmediaserver_7.9.1~1513951369_i386.deb

Step 6: Create directories for your playlists and music

LMS needs 2 different directories, one for media and one for playlists
You can decide where you want them

My media files were already on an external USB drive, that automounts at /media/mediadrive , so I didn’t need to create the directory, or copy my music files.

To keep things organized I created the playlist directory as a subdirectory of the media directory.
mkdir -p /media/mediadrive/squeezeboxplaylists

Step 7: Make sure that the server software will be able to access your media.

The LMS 7.9.1 server software runs under the “squeezeboxserver” user. (squeezeboxserver:nogroup)

You normally ssh into the ATV with default user “osmc”
I want both the squeezeboxserver and osmc users to have read+write access to the media files.

I created a new group “squeezeboxserver”
sudo groupadd squeezeboxserver

I then added “osmc” and “squeezeboxserver” to that group
sudo usermod -a -G squeezeboxserver osmc
sudo usermod -a -G squeezeboxserver squeezeboxserver

I then changed the group for the music directory AND ALL IT’S CONTENTS
sudo chgrp -R squeezeboxserver /media/mediadrive/

I then added permissions on the music directory AND ALL IT’S CONTENTS so that the group will have read/write acess
sudo chmod -R g+rw /media/mediadrive/

Step 8: Install the squeezebox software client

Normally LMS is designed to stream media to Logitech compatible hardware devices.
Since the ATV has audio output ports, we need to install a software "squeezebox player” so that we can also play audio though them.
I used “squeezelite - lightweight headless Squeezebox emulator - ALSA version”

Install squeezelite
sudo apt-get install squeezelite

List the audio outputs that squeezelite can use:

squeezelite -l

osmc@atv:~$ squeezelite -l
Output devices:
  null                           - Discard all samples (playback) or generate zero samples (capture)
  default:CARD=Intel             - HDA Intel, ALC889A Analog - Default Audio Device
  sysdefault:CARD=Intel          - HDA Intel, ALC889A Analog - Default Audio Device
  front:CARD=Intel,DEV=0         - HDA Intel, ALC889A Analog - Front speakers
  surround21:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 2.1 Surround output to Front and Subwoofer speakers
  surround40:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 4.0 Surround output to Front and Rear speakers
  surround41:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 4.1 Surround output to Front, Rear and Subwoofer speakers
  surround50:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 5.0 Surround output to Front, Center and Rear speakers
  surround51:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 5.1 Surround output to Front, Center, Rear and Subwoofer speakers
  surround71:CARD=Intel,DEV=0    - HDA Intel, ALC889A Analog - 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
  iec958:CARD=Intel,DEV=0        - HDA Intel, ALC889A Digital - IEC958 (S/PDIF) Digital Audio Output
  hdmi:CARD=Intel,DEV=0          - HDA Intel, HDMI 0 - HDMI Audio Output
  dmix:CARD=Intel,DEV=0          - HDA Intel, ALC889A Analog - Direct sample mixing device
  dmix:CARD=Intel,DEV=1          - HDA Intel, ALC889A Digital - Direct sample mixing device
  dmix:CARD=Intel,DEV=2          - HDA Intel, ALC889A Alt Analog - Direct sample mixing device
  dmix:CARD=Intel,DEV=3          - HDA Intel, HDMI 0 - Direct sample mixing device
  dsnoop:CARD=Intel,DEV=0        - HDA Intel, ALC889A Analog - Direct sample snooping device
  dsnoop:CARD=Intel,DEV=1        - HDA Intel, ALC889A Digital - Direct sample snooping device
  dsnoop:CARD=Intel,DEV=2        - HDA Intel, ALC889A Alt Analog - Direct sample snooping device
  dsnoop:CARD=Intel,DEV=3        - HDA Intel, HDMI 0 - Direct sample snooping device
  hw:CARD=Intel,DEV=0            - HDA Intel, ALC889A Analog - Direct hardware device without any conversions
  hw:CARD=Intel,DEV=1            - HDA Intel, ALC889A Digital - Direct hardware device without any conversions
  hw:CARD=Intel,DEV=2            - HDA Intel, ALC889A Alt Analog - Direct hardware device without any conversions
  hw:CARD=Intel,DEV=3            - HDA Intel, HDMI 0 - Direct hardware device without any conversions
  plughw:CARD=Intel,DEV=0        - HDA Intel, ALC889A Analog - Hardware device with all software conversions
  plughw:CARD=Intel,DEV=1        - HDA Intel, ALC889A Digital - Hardware device with all software conversions
  plughw:CARD=Intel,DEV=2        - HDA Intel, ALC889A Alt Analog - Hardware device with all software conversions
  plughw:CARD=Intel,DEV=3        - HDA Intel, HDMI 0 - Hardware device with all software conversions

Edit the config file so it uses, the correct audio output.
I will be using the analog RCA outputs for testing purposes

sudo nano /etc/default/squeezelite

# Defaults for squeezelite initscript
# sourced by /etc/init.d/squeezelite
# installed at /etc/default/squeezelite by the maintainer scripts

# The name for the squeezelite player:
SL_NAME="$(hostname -s)"

# ALSA output device:
SL_SOUNDCARD="default:CARD=Intel"

# Squeezebox server (Logitech Media Server):
# Uncomment the next line if you want to point squeezelite at the IP address of
# your squeezebox server. This is usually unnecessary as the server is
# automatically discovered.
#SB_SERVER_IP="192.168.x.y"

# Additional options to pass to squeezelite:
# Please do not include -z to make squeezelite daemonise itself.
#SB_EXTRA_ARGS=""

Step 9 : Create a free user account at www.mysqueezebox.com

Step 10: Start the server and squeezelite service

Start squeezebox server and check to see if it is running:
sudo systemctl start logitechmediaserver.service
sudo systemctl status logitechmediaserver.service

Start squeezelite and check to see if it is running:
sudo systemctl start squeezelite.service
sudo systemctl status squeezelite.service

Stop kodi to reduce system load:
sudo systemctl stop mediacenter

Step 11: Load the LMS server interface and configure it

Open a web browser and connect to the ATV1/Osmc box:
http://<ip of your box>:9000

Login with the mysqueezbox.com id/password you created in Step 9

Open the settings menu and configure where your media and playlist directories are.
When you save the settings, the media will be scanned. This will take a while.

The setting screen will also allow you to enable plugins/apps for tunein radio, spotify, SomaFM, Live Music Archive, etc. etc etc.

You can also add more apps by logging in the www.mysqueezebox.com website.

--------------------------------------------------------------------------------------------

Once you have things working correctly:

Enable LMS server and squeezelite to start automatically at boot time:
sudo systemctl enable logitechmediaserver.service
sudo systemctl enable squeezelite.service

Disable kodi from starting automatically
sudo systemctl disable mediacenter

Reboot the system
sudo reboot now

--------------------------------------------------------------------------------------------

Squeezelite player hangs when I am not playing music for a long time ?

I ran into this problem, and initally suspected it was a memory problem, because the 1st Gen ATV has very little ram.

After some investigation, I found that if I simply used LMS to virtually power the Squeezelite player off/on, it would work again. There was no need to reboot the device, or restart the LMS or Squeezelite software.

I eventually found this thread, that discusses into a different symptom when the squeezelite player if left idle for a long time, when running on debian.

http://forums.slimdevices.com/showthread.php?99916-workaround-for-pluginplayer-plays-quot-machingunsound-when-was-idle-some-time

I tested some of the scripts in that thread and found that the following version works well in osmc. Unlike the code in the first post of that thread, it doesn’t require lm_sensors to be installed.

The script will start/stop all squeezbox players that are not playing, or are paused, for longer than 2 minutes.

So far it has worked perfectly for me. Squeezelite has worked even if left idle for a long time.

--------------------------------------------------------------------------------------------

First create/open a file with nano:

sudo nano usr/local/bin/playercheck.sh

and paste the following code into it:

##!/bin/bash
## check if any player is playing
## and restart squeezelite if timetoplay is equal on both checks

##vars
port=9090
server=127.0.0.1
LOGFILE=/tmp/playercheck.log

#to use a fresh logfile use > below for each run
echo "============================================" > $LOGFILE
echo "$(date)" >> $LOGFILE

# get number of known players
players=$(printf "player count ?\nexit\n" | nc ${server} ${port} | cut -d ' ' -f 3)
echo "There are ${players} known players." >> $LOGFILE

## check all known players
for((i=0; i<${players}; i++))
do
  echo "" >> $LOGFILE
  playerID=$(printf "player id $i ?\nexit\n" | nc ${server} ${port} | cut -d ' ' -f 4 | sed 's/%/%%/g')
  playeron=$(printf "${playerID} power ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)
  playername=$(printf "$playerID name ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)

  if [ ${playeron} = '0' ]
  then
    echo "Player ${playername} is already powered off." >> $LOGFILE
  else
    playername=$(printf "$playerID name ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)
    echo "Player nr ${i} is called ${playername}." >> $LOGFILE

    timetoplay1=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)
    sleep 1
    timetoplay2=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)

    if [ $timetoplay1 = $timetoplay2 ]
    then
      echo "Player $playername is not playing right now. Checking if it is paused ..." >> $LOGFILE
      sleep 120
      timetoplay3=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' ' -f 3)
      if [ $timetoplay1 = $timetoplay3 ]
      then
        echo "Powering off ${playername}." >> $LOGFILE
        printf "$playerID power 0 \nexit\n" | nc $server $port 2>&1>/dev/null
      else
        echo "Player has resumed playing, all good !"
      fi
    else
      echo "Player ${playername} is playing fine." >> $LOGFILE
    fi
  fi
done

Save the file, and make it it executable:

chmod +x /usr/local/bin/playercheck.sh

Install cron:
sudo apt-get install cron

Edit crontab and add the following entry, to run the script every 30 mins:

sudo crontab -e

*/30 * * * * /usr/local/bin/playercheck.sh

--------------------------------------------------------------------------------------------

This sucks… how do I remove it ?

You can easily remove LMS and and enable kodi again:
sudo apt-get remove squeezelite
sudo apt-get remove logitechmediaserver
sudo systemctl enable mediacenter

--------------------------------------------------------------------------------------------

Notes:

  • LMS has a “local player” plugin, that will automatically install “squeezelite”, start it automatically when the LMS server starts, and allow GUI configuration. Automatic install did not work for me, therefore I manually installed “squeezelite” and configured it as a service. I suspect that manually installing “squeezelite” in addition to using the plugin, will cause problems.
1 Like

FYI you can run LMS with a command line switch to tell it not to use mysqueezebox.com so that you can see what things will be like when it is eventually switched off. You should find that it still works pretty well.
From memory the option is -nomysqueezebox

1 Like

Good info !

I notice you can toggle it in the settings menu too.

My biggest worry is that that you use mysqueezebox.com to install some of the “apps”
Hopefully the DIY commmunity and Logitech migrate away before the lights go out.

LMS on the ATV1 is great so far. I’m currently listening to Nils Frahm in flac (from 24bit wav) format while browsing ebooks in “Calibre”.
I’ll set up the DLNA bridge plugin later today and see if it can handle 2 streams at once.

At the goofy cost of Sonos gear, LMS and some small HiFiBerry based clients make a lot of sense.

I have edited the initial post to include info on how to solve squeezelite player hanging when idle for long periods.

Based on what info I’ve found online, it appears to be a problem with debian based installs

So far this has been working well.

I’ve got squeezer installed on our phones and also on the 10" android tablet that I have mounted on the wall as a high resolution photoframe/remote controller.