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. For example:

curl http://repo.merproject.org/obs/home:/wdehoog:/librespot/sailfishos_armv7hl/armv7hl/librespot-master_20180518-1.16.2.armv7hl.rpm -o librespot-master_20180518-1.16.2.armv7hl.rpm

devel-su pkcon install-local librespot-master_20180518-1.16.2.armv7hl.rpm

systemctl --user restart pulseaudio

Note that after installation pulseaudio really needs to be restarted due to permission to stream audio, see below.

The package also installs a systemd service file but the librespot service is not started automatically. To launch it use systemctl --user start librespot (as user nemo). You can edit /etc/default/librespot to suit your needs. Unfortunately I do not know how to get Librespot service started at boot. See Issue #11

Cargo, the rust builder, cannot download packages on demand on OBS so I needed to create a vendor archive. Unfortunately I could not create one that contained all required package versions so I manually edited the Cargo.toml and Cargo.lock files to 'fix' some dependencies.

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

Building locally

Getting cross-compiling working with pulseaudio enabled proved too hard for me so I have also built i 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.

Permission to stream audio

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

Device Discovery

As said discovery of the device is problematic. When used once from a real Spotify app the device shows up in lists. 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.

Note: from 2019-01-05 on hutspot has a dialog to register your Spotify credentials with Librespot. Se te PullDown menu in the Settings page. It can only work with librespot-master_20180518-1.20.1 or later (it needs to be able to read the passworden from stdin).