[HowTo] Spotify Connect on RPi1 with Raspbmc

This is a Raspbmc howto, not OSMC, but there dosn’t seem to be any other forum so I’m putting it here.
I’m still running Raspbmc on my RPi1 and wanted to have Spotify Connect working. Since I also had Volumio with the Spotify Connect plugin, I reused the work made for Volumio, since it includes a spotify key and a chroot setup working for RPi1. I’m not sure if this would work with RPi2/3, but add a comment if you have tried it.
There may very well be better alterantives for the “start on” definitions - I’m by no means an upstart or raspbmc expert - so feel free to add suggestions.

Download the package and unpack it:

$sudo wget https://github.com/balbuze/volumio-plugins/raw/master/plugins/music_service/volspotconnect/package/Volspotconnectchroot.tar.xz
$sudo tar -xf Volspotconnectchroot.tar.xz -C /
$sudo rm Volspotconnectchroot.tar.xz

Python complained when there was no passwd file in the chroot, so copy the normal one

$sudo cp /etc/passwd /data/plugins/music_service/volspotconnect/spotify-connect-web/etc/

Check which sound card index to use. List the cards you have and pick the one you need (In my case ”0” for HiFiBerry) :

$aplay -l | grep card
card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]

Now edit the sound configuration file in the chroot.

$sudo nano /data/plugins/music_service/volspotconnect/spotify-connect-web/etc/asound.conf

Change plughw:5,0 → plughw:0,0 (assuming you also want to use Card 0)
Change card 5 → card 0 (assuming you also want to use Card 0)
Save and exit with Ctrl-x - y - [Enter]

Create an ‘upstart’ file to start the service:

$sudo nano /etc/init/spotify-connect.conf

Paste the following, then set your user name and password correctly. You may also want to change the bitrate. Then save and exit

description "Spotify connect server based on Volumio plugin"

#The name you want to see in Spotify and on the network
env SPOTIFY_PLAYER_NAME='YourPlayerName'
#Your Spotify Premium user name
env SPOTIFY_USER='YourUserName'
#Your Spotify Premium password
env SPOTIFY_PSW='YourPassw'

#Spotify arguments. 
env ARGS="--username $SPOTIFY_USER --password $SPOTIFY_PSW --bitrate 320 --name $SPOTIFY_PLAYER_NAME --playback_device 'softvolume' --mixer 'SoftMaster'  --mixer_device_index 0 --dbrange 45"
#The directory where the plugin chroot is placed
env DIR=/data/plugins/music_service/volspotconnect/spotify-connect-web
#Log file for debugging
env LOGF=/var/log/spotify-connect.log
#Export this to be used by the avahi job
export SPOTIFY_PLAYER_NAME

#Start after the wireless setup, then everything should be ready
start on started wireless
stop on runlevel [016]

script
   #Redirect output for debugging
   exec >> $LOGF 2>&1
   exec $DIR/spotify-connect-web $ARGS
end script

post-stop script
    # clean up
    exec >> $LOGF 2>&1
    #The proc mount seems to be removed automatically, but not the dev mount. I don't understand why but this is working
    umount -lf $DIR/dev
    #umount -lf $DIR/proc
end script

If you want the web server to be announced via Zeroconf (not relevant if you don’t plan to use the web interface much), also create the following file.

$sudo nano /etc/init/spotify-connect-zconf.conf

Paste this content, save and exit:

description "Zeroconf publisher for the spotify connect web server"
start on started spotify-connect and started avahi-daemon
stop on stopped spotify-connect or stopped avahi-daemon

#Log file for debugging
env LOGF=/var/log/spotify-connect-avahi.log

script
   #Redirect all output to log file
   exec > $LOGF 2>&1
   echo "Starting"
   date
   #Assign a default player name if not done by another script
   [ -z "$SPOTIFY_PLAYER_NAME" ] && SPOTIFY_PLAYER_NAME="SpotifyConnectPlayer"
   echo "Player name: " $SPOTIFY_PLAYER_NAME
   avahi-publish-service -s $SPOTIFY_PLAYER_NAME _spotify-connect._tcp 4000 VERSION=1.0 CPath=/login/_zeroconf
end script

Restart the RPi

$sudo shutdown -r now

Check that the services are running

$ status spotify-connect
spotify-connect start/running, process 1521
$ status spotify-connect-zconf
spotify-connect-zconf start/running, process 1541

If you run your spotify client on PC/smartphone, you should now see your RPi as an “Available unit”

Done!

Raspbmc was never released for Pi 2 or Pi 3, so the instructions won’t work.

Thanks for the tutorial, but I am curious why you are still using Raspbmc and haven’t updated to OSMC. There have been a lot of improvements.

While the tutorial seems fine, I don’t think you will get a lot of people trying it as not many people use Raspbmc anymore. Thanks for taking the time to write it though.