Configuring Spotifyd on a RaspberryPi - Tue, Dec 31, 2024
This document is paired with a video linked below. The idea is to get easy access to Spotify in an older car.
The general premise behind this small life hack comes from the fact that I own an older car that can’t stream music over bluetooth. I bought a bluetooth dongle, previously, but that one stopped working after a while. Besices: Spotify Jam sharing with other passengers in the car is kinda cool on longer trips.
Here is what you are going to need:
- 1x RaspberryPi with proper audio-out interface: preferable RPi3 or RPi4
- 1x microSD card of any size: 4GB is enough, but you can use a bigger one for cache
- 1x USB power wire and a power adapter, depending on your car
- 1x audio cable to transfer audio from the RPi to the cars’ stereo
- A computer with RaspberryPi Imager installed
- A HDMI-capable monitor and a keyboard for iniotial configuration purposes
With RaspberryPi Imager you will flash Bookworm Lite 32-bit version on your microSD. Use the microSD adapter for this step if needed. Before flashing starts make sure to setup WiFi to the hotspot settings of your smartphone. I recommend enabling SSH as well, for optional remote troubleshooting in the future. Once flashing is done insert the microSD card into your RaspberryPi and give it 5-10 minutes too finish expanding the filesystem. First boot is the longest. Once it boots up fully, login with credentials that you have set with Imager software and use sudo apt update && sudo apt full-upgrade to get the whole OS to a fully up-to-date state and then reboot once again.
The operating system is now ready to fetch Spotifyd from the URL below:
Make sure to download full version marked as armhf - that one is for ARMv7 32bit. At the moment of writing this article, 64bit binary did not exist, yet. You can use wget to download the archive directly to your RPi.
Now unarchive the downloaded file with tar zxvf spotifyd-linux-armhf-full.tar.gz and you will get one new file called spotifyd which will already have the executable bit set. At this point you can already try to execute this file with ./spotifyd –no-daemon to check if it’s working. If it is working kill it with CRTL+C so we can continue with the configuration.
Create a confing folder with mkdir -p ~/.config/spotifyd/ and then edit the config file with nano ~/.config/spotifyd/spotifyd.conf in which you will want to paste all of the below:
[global]
#username = "USER"
#password = "PASS"
backend = "alsa" # use portaudio for BSD
device = "alsa_audio_device"
control = "alsa_audio_device"
mixer = "PCM"
volume_controller = "alsa" # use softvol for BSD
device_name = "Your_Car_Name" # No spaces
bitrate = 160 # 96 or 320 are available as well
cache_path = "/tmp/spotifyd"
max_cache_size = 100000000
#no_audio_cache = true
initial_volume = "100"
volume_normalisation = true
normalisation_pregain = -10
autoplay = true # autoplay similar music after playlist is done
device_type = "speaker" # this changes the icon
This should be everything needed for the configuration of the software. What follows is making the whole thing automatically startup on boot.
First make sure you have the user Systemd folder prepared with mkdir ~/.config/systemd/user/ and then edit the systemd service file with nano ~/.config/systemd/user/spotifyd.service while being careful to edit ExecStart line with the path where you extracted the daemon executable.
[Unit]
Description=A spotify playing daemon
Wants=sound.target network-online.target
After=sound.target network-online.target
[Service]
ExecStart=/home/pi/spotifyd --no-daemon
Restart=always
RestartSec=12
[Install]
WantedBy=default.target
Now give your user (pi is the default user if you haven’t changed it) pi the power to run stuff while not logged in with sudo loginctl enable-linger pi After that make sure to enable the script to autostart on boot with systemctl –user enable spotifyd.service
Feel free to reboot at this point and keep your smartphone hotspot running. On fresh boot RaspberryPi OS should connect to the internet automatically via your phone and Spotifyd should be reachable via Spotify app on the same smartphone. You can check if the music is working by plugging in standard headphones.
If you are perfectly happy with how things work on boot there is one optional step to make your filesystem completely non-writable. The idea behing this is so you can simply turn off your car ans cut the power to the RaspberryPi without any fear of data corruption. The downside is that music cache will be gone every time. In order to do this run sudo raspi-config, go to Performance Options and enable overlay filesystem and make the boot partition non-writable. Reboot afterwards to make the final check that everything is working as expected and install the RaspberryPi into your car or wherever you have the need to play Spotify on external speakers.
Please watch the acompanying video on your prefered video platform:
- PeerTube: https://tux-edu.tv/w/dSJvqP328ZSNK3YTn7ze8X
- Odysee: https://odysee.com/@LinuxRenaissance:1/spotifyd:f
- YouTube: https://www.youtube.com/watch?v=dsiI9Vg0mOY