Skip to content

Instantly share code, notes, and snippets.

@wdehoog
Last active July 20, 2018 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdehoog/d83d75564ebc77a985384950af44ee7c to your computer and use it in GitHub Desktop.
Save wdehoog/d83d75564ebc77a985384950af44ee7c to your computer and use it in GitHub Desktop.
turn sailfish device into spotify connect player

You can turn your sailfish device into a Spotify Connect Player using Librespot. (For as long as Spotify supports the old api.)

When building LibreSpot you get an executable that can be used as a Spotify Connect Player. It shows up in the Spotify app and webbased player. With some luck it also appears in the list received with getMyDevices (web api).

Build on OBS

On OBS you can find a package to install it on Sailfish. It also installs a systemd service file but librespot is not started automatically. To start it use systemctl --user start librespot. Edit /etc/default/librespot to suit your needs. If you do want to have it start at boot see the last lines in /etc/systemd/user/librespot.service. Note that after installation pulseaudio needs to be restarted, see below.

Build it

Getting cross-compiling working with pulseaudio enabled proved too hard for me so I have built on a BananaPi. Should probably work on a RaspberryPi as well. For pulseaudio you also need to install libpulse-dev.

Building is done with:

cargo build --release --features "alsa-backend pulseaudio-backend"

There is an Issue about cross compiling with pulseaudio support: Docker compile with pulseaudio backend fails. At the and a solution is presented but I did not try it.

Since the kernel on my phone (Oneplus One) is old (3.4.67) I needed to patch librespot see Librespot for kernel < 3.9.

To allow LibreSpot to use pulseaudio (and have a non muted sink-input) create /etc/pulse/xpolicy.conf.d/librespot.conf: (as root)

[stream]
exe      = librespot
group    = player

Restart pulseaudio (or reboot). (as nemo)

systemctl --user restart pulseaudio

Launching the player is done for example with: (as nemo)

./librespot -n Sailfish -b 320 -v --backend pulseaudio

As said discovery of the device is problematic. When used once from a real Spotify app the device shows up in lists. Maybe using the commandline options --username and --password will make it show up for a while.

However now the password will be visible in the process list and service status. Only specifying the username will make librespot ask for the password. If the cache is enabled the credentials will be stored there. So if you start in once from the command line like:

librespot --cache /home/nemo/.cache/librespot --username <USERNAME> -n test 

the service can use the cached credentials without showing it in the process or service lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment