Raspberry Pi 3 as Spotify player
This is how I turned a Raspberry Pi 3 into a Spotify player, to control with any Spotify client featuring Spotify Connect (typically on a smartphone or tablet).
Configuring the Pi for playback through a DAC
I chose the PiFi DAC V2. It is cheap, outputs a decent analog audio quality and works almost out of the box with the RPI 3. You just have to open /boot/config.txt and uncomment or add the folllowing lines:
dtparam=i2s=on dtoverlay=hifiberry-dacplus dtparam=audio=off
The last line disables the loading of the snd_bcm2835 kernel module and hence the onboard audio output. For more info over this DAC on others on a Pi, see How to make various DACs work.
Install Spotify Connect Web
Spotify Connect Web is a python wrapper of the deprecated but yet unreplaced libspotify library for ARM platforms. There are various ways to install it. I went for the most straighforward, using a latest packaged release. The package contains everything needed except the required binary application key (spotify_appkey.key) that you can get from https://developer.spotify.com/my-account/keys. Note that you will need a Spotify Premium account too.
wget https://github.com/Fornoth/spotify-connect-web/releases/download/0.0.3-alpha/spotify-connect-web_0.0.3-alpha.tar.gz tar zxvf spotify-connect-web_0.0.3-alpha.tar.gz sudo mv spotify-connect-web /usr/local/lib/spotifyconnectweb sudo chown -R root:staff /usr/local/lib/spotifyconnectweb
I made two systemd scripts to launch spotify-connect-web automatically at startup, along with a config file. Get the archive here. Once expanded, it provides three files:
- spotifyconnectlogin.service (which publishes the zeroconf login service)
- spotifyconnectweb.conf (the configuration file)
- spotifyconnectweb.service (which launches spotify-connect-web as a daemon)
Put spotifyconnectweb.conf and the application key from Spotify (spotify_appkey.key) in /etc/spotifyconnectweb:
sudo mv spotifyconnectweb.conf /etc/spotifyconnectweb/ sudo mv spotify_appkey.key /etc/spotifyconnectweb/
Put both .service files in /etc/systemd/system and enable the services:
sudo mv spotifyconnectlogin.service /etc/systemd/system/ sudo mv spotifyconnectweb.service /etc/systemd/system/ sudo systemctl enable spotifyconnectweb sudo systemctl enable spotifyconnectlogin
Check the content of /etc/spotifyconnectweb/spotifyconnectweb.conf and adjust according to the hardware (the playback device and mixer values given here and in the archive are for a PiFi DAC V2):
INSTALLPATH=/usr/local/lib/spotifyconnectweb PLAYBACK_DEVICE=plughw:0 MIXER=Digital KEY=/etc/spotifyconnectweb/spotify_appkey.key NAME=raspberrypi BITRATE=320
Note that all variables are required by the spotifyconnectweb service. If you delete a line here, the corresponding parameter must be deleted in spotifyconnectweb.service as well.