Spotify
The speaker plays Spotify in two ways:
- Spotify Connect: in the Spotify app, choose the speaker as the device to play on. Anyone with Spotify Premium on the speaker's network can, once the owner gave the speaker an API key for Spotify's receiver.
- Your playlists on the speaker's pages: connect your account once under Settings → Spotify, and your Spotify playlists show under Playlists, next to the speaker's own, and play from there.
Both need Spotify Premium: Spotify plays on other devices for Premium accounts only.
Spotify Connect
The receiver is Spotify Soloist, Spotify's own. It runs only with an API key, made once by a Premium account:
- Log in at developer.spotify.com, open Spotify Soloist API Key (see Spotify's getting started), accept the terms and generate a key.
- Paste it under Settings → Spotify and press Save.
The key belongs to the account that made it: keep it to yourself. The speaker keeps it for root alone (/var/lib/boombox/spotify-receiver.env); Remove key takes the speaker out of the Spotify app.
Spotify does not allow passing Soloist on, so the speaker downloads it from Spotify itself (boombox-spotify-update), right after an install and then every week: a build runs for 90 days. Until the first download is done, Settings → Spotify says so.
Then, to play:
- Join the speaker's Wi-Fi network with your phone.
- In the Spotify app, tap the devices button and choose the speaker. It is listed under its network name (
boomboxunless you renamed it under Settings → System).
Now playing shows the song with its cover, a green Spotify tag and how far the song is. Previous, Play/Pause and Next work there as in the app, and the progress bar jumps within the song, and so do the knob's presses on the display and Home Assistant's media player. With a Spotify account connected (below), Play on the speaker plays there, also when Spotify last played on another device. Choose songs in the Spotify app. Disconnect on the speaker pauses and gives up the speaker: the app shows another device again.
With a Spotify account connected (below), Play Spotify here on Now playing, and at the top of the display's Playlists menu, moves what Spotify plays on that account, on your phone or anywhere, to the speaker: no need to choose it in the app. It follows Something new starting to play under Settings → Audio → Playback: a speaker that keeps what plays asks first, with Play anyway.
Spotify plays like a phone does:
- Starting to play takes over from what plays, a phone or a playlist. With Settings → Audio → Playback set to wait, Spotify is refused while something else plays.
- Something else taking over ends the Spotify session. Spotify does not pick up again afterwards: start it again in the app.
- An announcement from Home Assistant ends it too.
- Only what plays on this speaker counts. Several speakers on one account each leave Spotify on another of them alone. A speaker that another one took Spotify from shows its song paused: Play there, or a press on its knob, takes Spotify back.
The speaker's volume and its volume limit apply: Soloist plays through a PulseAudio of its own (boombox-spotify-pulse) into the speaker's mixer. The app's volume slider turns Soloist down within that. Spotify is not recorded under Recordings. PulseAudio runs only with the receiver and lets go of the sound card 3 seconds after Spotify stops; the songs Soloist fetched stay in RAM (50 MB), not on the SD card.
To use another name in the Spotify app, put it in /etc/boombox/spotify.env and restart the receiver:
echo 'SPOTIFY_NAME=Boombox Kitchen' | sudo tee /etc/boombox/spotify.env
sudo systemctl restart boombox-spotifyThe speaker used librespot before. Spotify refuses librespot the songs' keys on more and more accounts (every song skips after a few seconds, without sound: librespot#1649), so it plays Soloist now. An update removes librespot's hook, masks raspotify's own receiver and renames LIBRESPOT_NAME.
Connecting your account
Spotify lets a speaker see your playlists only through an app of your own on Spotify's developer site. It is free and takes a few minutes.
- Log in at developer.spotify.com/dashboard with the Premium account whose playlists you want, and choose Create app. Name and description are up to you.
- As Redirect URI, add exactly
http://127.0.0.1:8888/callback, tick Web API, and save. - Copy the app's Client ID (under Basic Information) into Settings → Spotify and press Connect. The speaker does not need the Client secret: keep it to yourself.
- Press Agree on Spotify, log in if Spotify asks, and agree.
- The browser then shows a page that cannot be reached. That is right: copy that page's whole address from the address bar, paste it under Address and press Finish.
The page then shows the connected account. The speaker keeps it, also after a restart, until you press Disconnect.
Why the pasted address: Spotify sends the browser back with a code, and allows plain http:// only to 127.0.0.1, the computer the browser runs on. The speaker has no certificate for https:// (see Architecture → Security model), so it cannot receive the code itself; you carry it over. The code works once and only for a few minutes.
Spotify keeps an app like this in development mode: its owner needs Premium, and up to five accounts can use it. Another account than the app's owner must first be added under User Management in the app's settings.
Your playlists
With an account connected, Playlists lists its playlists after the speaker's own. Each has a green Spotify tag, its number of songs and whose it is. Opened, its songs carry the tag too, and the song Spotify plays on the speaker is marked.
Spotify's playlists are read-only here: rename them, delete them or change their songs in Spotify. Playlists you follow but do not own (Discover Weekly, other people's) show without their songs, as Spotify shows songs of your own playlists only. They play all the same.
Play asks Spotify to play the playlist on the speaker's receiver, from the start or from a song. For that the receiver must be logged in to your account: choose the speaker once in the Spotify app, logged in to the same account. The receiver keeps that login, also after a restart. The playing song carries a line of how far it is; a click on the line jumps there, as on Now playing.
Spotify does not always list a logged-in receiver among the account's devices (it then answers "Not found" or "Bad gateway"). The speaker then makes its receiver the account's active device, as choosing it in the app does, and looks again for a few seconds. If Spotify still does not list it, the receiver plays the playlist itself and skips on to the song asked for, which takes a few seconds more. Play Spotify here goes on with what the account played last the same way. The agent's log says which devices Spotify listed.
Playing from a song plays the playlist in order: the speaker switches the account's shuffle off first, so Next and Previous on Now playing go to the neighbouring songs (shuffle it again in the app if you like). Spotify sometimes reports a failure for a play it carried out; a receiver found playing after such an answer is left alone, so the song does not start over. While the receiver is being started again (after an update, or when it crashed), a control is refused with "The Spotify receiver is not reachable" instead of being lost.
What does not work:
- Changing playlists, or saving songs, from the speaker.
- Songs that are files on your computer ("local files") are listed as unavailable.
Security
- The account's refresh token stays in the agent's settings (
/var/lib/boombox/config.json, root only). Pages only learn the account's name, the Client ID and whether a connection is waiting for its address. - The agent talks to Spotify with curl as
nobody, and hands it the tokens on its standard input, never on its command line, where every user of the board could read them. - There is no client secret: the speaker connects with PKCE.
- The TV's account can play Spotify playlists with playback access, but never connect or disconnect an account.
- Disconnect forgets the account on the speaker. To take back the access on Spotify's side too, remove the app under Manage apps at spotify.com/account.
- The receiver runs as
boombox-spotify, sandboxed, and plays through the speaker's mixer, so the volume limit holds. Its login for Spotify Connect is in/var/lib/boombox-spotify(mode 0700). - Soloist takes the API key only on its command line:
ProtectProc=invisiblehides the process from other users. Its local API (127.0.0.1:47917) has no authentication and listens on loopback only; the agent follows it. - Soloist comes from
soloist-builds.spotifycdn.comover https only; Spotify publishes no checksum for it.
Troubleshooting
| Symptom | What to do |
|---|---|
| The Spotify app does not list the speaker | Settings → Spotify needs the API key. The phone must be on the same network, which must let devices see each other (no guest network or client isolation). Check systemctl status boombox-spotify boombox-spotify-pulse. |
| Settings → Spotify: "The speaker is downloading Spotify's receiver" for long | The speaker needs the internet once. sudo systemctl start boombox-spotify-update and journalctl -u boombox-spotify-update show why. |
| Songs skip after a few seconds, no sound; the log says "audio key error" | That was librespot, which Spotify refuses. Update the speaker: it plays Soloist. |
| Clicks every few seconds while nothing plays | journalctl -u boombox-spotify shows the receiver failing and restarting. Each restart used to restart its PulseAudio too, which opens the sound card: the DAC pops without an amplifier pin. Fix what the log names. |
journalctl -u boombox-spotify says the build expired | sudo systemctl start boombox-spotify-update: a newer build replaces it, and the receiver starts. |
| Play: "The speaker is not on your Spotify account yet" | Choose the speaker once in the Spotify app, logged in to the connected account. If the app does not list it, the receiver is not running: see the row above and systemctl status boombox-spotify. |
| Spotify: "INVALID_CLIENT: Invalid redirect URI" | The app's Redirect URI must be exactly http://127.0.0.1:8888/callback. |
| "This address belongs to an earlier try" | You pressed Connect again after opening Spotify. Use the newest Agree on Spotify. |
| "Spotify did not take this address" | The code is used, or older than a few minutes. Connect again. |
| Spotify: "User not registered in the Developer Dashboard" | Add the account under User Management in the app's settings. |
| "Spotify answered 403: Check settings on developer.spotify.com/dashboard, the user may not be registered" | The account you agreed with is not the app's owner and not under User Management, or the app's owner has no Premium. Add the account (name and Spotify e-mail), then press Connect again. |
| "Spotify ended the connection" | The app's access was removed, or the app was deleted. Connect again. |
| "Player command failed: Premium required" | The connected account has no Premium. |
journalctl -u boombox-spotify -u boombox-spotify-pulse -u boombox-spotify-update shows the receiver, its sound and its downloads; journalctl -u boombox-agent | grep -i spotify what the agent asked of Spotify.