Skip to main content

Use Librespot to play songs

Overview

librespot is an open source client library for Spotify. It enables applications to use Spotify's service to control and play music and to act as a Spotify Connect receiver. Using this terminal-application in combination with a Spotify-controller like Hutspot, you can play songs from Spotify on your SailfishOS-Device without using the Android-app from Spotify itself. The source code is available on GitHub

Installation

Prebuilt package

ATTENTION: Currently (22.1.2026) this package DOES NOT work with 32-Bit devices (e.g. Sony Xperia XA2 series, Xperia 10,...). If you want to use Librespot on these devices, you might try build it yourself (see tutorial below)(no guarantees it will work, not tested by the author of this wiki)

NOTE: This package provides version 0.6.0 which is outdated. The latest version as of 21.7.2026 is 0.8.0 which you can get when building yourself.

There is a prebuilt package which a user uploaded to the forum. You can download it here (just click on     librespot-0.6.0-1.31.1.bso.aarch64.rpm and it will download) . If you want to change the configuration, you can edit the command in the file /etc/systemd/user/librespot.service(see instructions below). This package installs Librespot as a service, so you can start and stop it from Hutspot directly.

Building it yourself

You can also get librespot directly an build it on your device. First, you need to install Rust. To do this, open a terminal and execute 

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After the installation has finished,  you need to restart your session. This can be done by just typing bash and hitting enter. You also need to install a few development packages. To install these, type in a terminal

devel-su pkcon refresh
devel-su pkcon install gcc git alsa-lib-devel -y

Now that you have everything necessary installed, you can get the source code from GitHub

git clone https://github.com/librespot-org/librespot
cd librespot/

After that, you can now build your application using cargo:

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

Installing Librespot as a service

If you want to control Librespot from Hutspot, you need to install it as a service. If this was not already done with the installation of the prebuilt package, create a file librespot.service under /etc/systemd/user (you need administrator privileges for that, so use devel-su in the Terminal, e. g. devel-su nano /etc/systemd/user/librespot.service ). 

In this file, paste the following: 

[Unit]
Description=Librespot
After=network.target

[Service]
ExecStartPre=/bin/mkdir -m 0755 -p /home/defaultuser/.cache/librespot
Environment="DEVICE_NAME=Librespot-%H"
Environment="CACHE_ARGS=/home/defaultuser/.cache/librespot"
Environment="VOLUME_ARGS=--enable-volume-normalisation --initial-volume=100"
Environment="BACKEND_ARGS=--backend pulseaudio"
Environment="DEVICE_TYPE_ARGS=--device-type smartphone"
Environment="BINARY_PATH=/home/defaultuser/librespot/target/release/"
Environment="USER_ARGS=<YOUR USERNAME>"
ExecStart=/bin/env "PULSE_PROP_media.role=x-maemo" /home/defaultuser/librespot/target/release/librespot --name ${DEVICE_NAME} $BACKEND_ARGS --b 320 --cache $CACHE_ARGS --username $USER_ARGS $VOLUME_ARGS $DEVICE_TYPE_ARGS

Change <YOUR USERNAME> to your Spotify username. If you have cloned the Librespot git-Repository to another location, change /home/defaultuser/librespot/ to the location pointing to your Librespot directory. 

IMPORTANT: In order for this to work, you need to start Librespot once from the terminal to put in your password. For this, refer to the instructions in the section "Usage". After successfully logging in, you can close the terminal and do everything else in the GUI.

Now you can control Librespot with Hutspot (see below). By default, you can start/stop Librespot with Hutspot, or let Hutspot do that for you. You can also let Librespot start at boot. If you want this, change line 3 of the librespot.service-file to the following: 

# for start at boot you might want:
After=user-session.target network.target pulseaudio.service

Additionally, add the following to the end of the file:

[Install]
WantedBy=post-user-session.target

Unfortunately boot will fail probably since there is no network device. To enable those changes, run in the Terminal: 

systemctl --user enable librespot

(To disable again, use disable instead of enable )

Usage

Controlling Librespot with Hutspot

If you have installed Librespot as a service AND have started Librespot once from the terminal to put in your credentials (see below), you can control Librespot right from the GUI of Hutspot. To do this, tap on the Hamburger-menu (four lines)  in the bottom right corner of Hutspot and navigate to Settings. There, you need to activate "Control Librespot" (Like seen in  this screenshot ). This will start Librespot with Hutspot and terminate it when Hutspot is closed.  On this page, you can also start/stop Librespot manually. This is also possible from the Pull-Down-Menu of the Devices-page (Like seen here).

Starting Librespot from the terminal

You can also start Librespot from the terminal, where you can make your configuration directly. If you have built Librespot yourself, you need to execute Librespot from the path where you built it. The executeable is typically stored under <PATH TO LIBRESPOT SOURCE>/target/release/.  For more overview of which options are possible for Librespot, you can look here.

Generally, you would want the --username option,  the --cache option (so you don't need to type in your password everytime), the -n option to give the instance a name and the --backend option (which needs to be set to pulseaudio).

An example command could look like this:

/home/defaultuser/librespot/target/release/librespot --cache /home/defaultuser/.cache/librespot --username <YOUR USERNAME> -b 320 -n MyAwesomeLibrespotBuild --backend pulseaudio --device-type smartphone

NOTICE: If you launch Librespot this way, you won't be able to control its volume via the volume-buttons on your device, you can only control it via the volume-slider in Hutspot. If you want to use the volume-buttons, you need to execute Librespsot in the following way: 

/bin/env "PULSE_PROP_media.role=x-maemo" <YOUR LIBRESPOT COMMAND LIKE ABOVE>


Setting Librespot as the current device

If Librespot is running, you can use it to play songs from Spotify via Hutspot. To do this, open Hutspot and navigate to the Devices-page. All connected Spotify devices will show up there (which includes Librespot-instances). To use a device, long press on the device and choose "Set as active device" (first option in the menu). Congratulations, you can now play, pause and skip songs via Hutspot which will be played using your SailfishOS-smartphone.

Bildschirmfoto_20230923_002.png

Known Issues / Working versions

Known issues

  • Starting Librespot, especially connecting to Spotify's Servers can sometimes take a very long time. Sometimes you need to try it a few times until it connects.
  • Libresspot sometimes randomly crashes. Just restart it either via Hutspot or in the terminal with systemctl --user restart librespot

Working versions

Working?
Librespot version
SailfishOS-Version
Device tested on
Comments
YES
0.8.0
5.1.0.11
Sony Xperia 10 III