spotify-player icon indicating copy to clipboard operation
spotify-player copied to clipboard

spotify-player device disappears after some time

Open contonice opened this issue 8 months ago • 5 comments

Describe the bug I'm trying to use this app as a backend for a smart speaker. My setup: raspberry pi with wired internet, usb sound card and speakers. I am running the application in daemon mode using -d flag and systemd. Then, when I want to listen to music, I open spotify on my phone and use spotify connect to turn on the track on raspberry. This works immediately after running the script. But if a certain amount of time passes (one night for example), the spotify-player device will disappear. However, the application does not die, the process remains run in the system.

To Reproduce

  1. Install an application with a flag to run as a daemon.
  2. Change the ID in the config to your application created in the spotify api.
  3. Launch the application with the -d flag.
  4. Launch spotify on your phone and make sure that there is a spotify player in the list.
  5. Wait a few hours.
  6. Launch spotify on your phone again and see that the spotify player has disappeared.

Optional: 7) Kill the player process and launch it again (or use systemctl restart). 8) Open spotify on your phone. 9) spotify-player is working again.

Expected behaviour As long as application working, there is spotify-player on phone.

Log and backtrace Backtrace is empty. Here is log: https://drive.google.com/file/d/1AnGfBljq5IlkNGm4FwOR0mpmsixZhcmY/view

Environment

  • OS: Latest Raspberry Pi OS (Linux rpi 6.6.74+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.74-1+rpt1 (2025-01-27) aarch64 GNU/Linux)
  • Application version: 0.20.4
  • Application features: cargo install spotify_player --features daemon

Additional context

My systemctl config:

[Unit]
Description=Spotify Player daemon
After=network.target

[Service]
Type=forking
ExecStart=/home/contie/.cargo/bin/spotify_player -d
Restart=on-failure

[Install]
WantedBy=default.target

contonice avatar Apr 05 '25 05:04 contonice

I was going to create an issue about this, it's true that when you go idle for 5-10 minutes, the streaming pauses. Though I think the problem is not from spotify-player but librespot, but that makes spotify-player daemon, not really a daemon.

Another solution is to disable the streaming on spotify-player and use spotifyd instead. Spotifyd never dies idle and has a service for systemd. You can use spotify-player using spotifyd as a device but it's not necessary but you'll likely need a spotify connect API for spotify-player (to make the device showing on the list of devices).

arc-d3v avatar Apr 24 '25 16:04 arc-d3v

Another solution is to disable the streaming on spotify-player and use spotifyd instead. Spotifyd never dies idle and has a service for systemd. You can use spotify-player using spotifyd as a device but it's not necessary but you'll likely need a spotify connect API for spotify-player (to make the device showing on the list of devices).

Weird cause spotifyd also uses librespot under the hood, so the same thing should happen unless the version of librespot is different between spotify_player and spotifyd.

Looking into the logs, this seems to be the problem

2025-04-04T15:25:22.921036Z ERROR librespot_connect::spirc: ContextError: Error { kind: Unknown, error: StatusCode(502) }    

so it's librespot issue but I don't know why it happened

aome510 avatar May 10 '25 15:05 aome510

Another solution is to disable the streaming on spotify-player and use spotifyd instead. Spotifyd never dies idle and has a service for systemd. You can use spotify-player using spotifyd as a device but it's not necessary but you'll likely need a spotify connect API for spotify-player (to make the device showing on the list of devices).

Weird cause spotifyd also uses librespot under the hood, so the same thing should happen unless the version of librespot is different between spotify_player and spotifyd.

Looking into the logs, this seems to be the problem

2025-04-04T15:25:22.921036Z ERROR librespot_connect::spirc: ContextError: Error { kind: Unknown, error: StatusCode(502) }    

so it's librespot issue but I don't know why it happened

This error is only showing only with spotify-player though. When I use spotify_connect with spotifyd, I don't get a 502 when I use a device other than spotify-player. You can reproduce it pretty easily, connect spotify-player (streaming off) to spotify connect, and spotifyd to spotify connect, start any song with spotify-player while connected to spotifyd as a device, then you'll see the error. Do the same thing with but start the song with any backend device (phone or official app) and you get no error.

There are a lot of sync issue as well with spotify-connect connected in another backed device through spotify-connect, but that's another issue.

Though the error is showing at start, it doesn't cut the stream, the stream is cut off randomly after a few hours of use.

Seems it's related to #710 .

arc-d3v avatar May 10 '25 18:05 arc-d3v

So after some test, I discovered that it happens with spotifyd as well but less often. It happens when a tiny disconnection or a change on the network happens, librespot doesn't have anything to reconnect to spotify connect so the playback stops. So you were right, it's only a librespot issue, not spotify player or spotifyd.

arc-d3v avatar May 31 '25 07:05 arc-d3v

For me it's been a while no devices show up, regardless. It plays on my computer if I start afresh, but never showing anything in the devices bar. Give it some pauses and context switching and back, then playing on my laptop (Linux) does not work anymore, unless starting afresh:

Image

glima avatar Sep 22 '25 17:09 glima