mirror of
https://github.com/librespot-org/librespot.git
synced 2026-04-27 00:05:55 +03:00
[GH-ISSUE #1506] librespot does not release ALSA device after Spotify Connect stream finishes #680
Labels
No labels
A-Alsa
SpotifyAPI
Tokio 1.0
audio
bug
can't reproduce
compilation
dependencies
duplicate
enhancement
good first issue
help wanted
high priority
imported
imported
invalid
new api
pull-request
question
reverse engineering
wiki
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/librespot#680
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @frialey63 on GitHub (Jun 7, 2025).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/1506
Version
librespot 0.6.0 VERGEN_IDEMPOTENT_OUTPUT (Built on 2025-05-31, Build ID: 8j6X3B4v, Profile: release)
How to reproduce
When librespot has finished playing a stream using Spotify Connect, I then attempt to play a local file using mpd (running on the same sever as librespot and configured to output to the same ALSA device) but no sound is heard.
Command
Host
Linux pi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux
Additional context
If I disable librespot and enable librespot-player (Java) then this operation works as expected. The librespot-player has a configurable parameter
releaseLineDelaywhich demonstrates that it is designed to release the ALSA device after it has finished playing.@photovoltex commented on GitHub (Jun 7, 2025):
This sounds quite similar to the observation in #1500. Could you give https://github.com/photovoltex/librespot/tree/reduced-sink-usage a try? The TL;DR; would be that we don't close the audio sink while we don't play any audio. We could also add a similar parameter to the binary and the delay after stopping playback. But the branch previously mentioned is just a poc if it would fix the issue. Thanks in advance for the testing :)
@frialey63 commented on GitHub (Jun 7, 2025):
I have built the release of librespot from branch
https://github.com/photovoltex/librespot/tree/reduced-sink-usageand when run with the same options it encounters the same problem. While librespot is running Spotify streams play fine but when a stream is finished it is not possible to switch to mpd and play (hear) a local file. I have waited 30secs and 60secs after the stream was finished. In order to play and hear the local files via mpd it is necessary to stop the librespot process.This problem does not occur when using librespot-player, it is possible to switch between playing Spotify streams and local files from mpd while these two services are both up and running continuously. (Subject only to waiting for
releaseLineDelayafter a stream has finished.)@photovoltex commented on GitHub (Jun 8, 2025):
Thanks for the quick testing. A bummer that it isn't such an easy fix. I will look into it when I'm back home. The best case would be to just carry over what librespot-java does, but could be a bit more tricky depending on the infrastructural differences.
@kdistin commented on GitHub (Jun 21, 2025):
I have librespot and mpd running on the same server.
I do not see this problem. As soon as I stop librespot playback I can play a local file with mpd.
My librespot options are:
--backend alsa --bitrate 320 --device hw:0,0 --device-type computer --disable-audio-cache --alsa-mixer-control Master --initial-volume 100@frialey63 commented on GitHub (Jun 22, 2025):
OK, looking at your options I see that you are using the
alsabackend whereas I have been using therodiobackend because this seems to the preferred (default) backend for librespot. When I get time, I will do a test withalsaand report back.@spockfish commented on GitHub (Aug 25, 2025):
I can confirm having the same issue.
@roderickvd commented on GitHub (Aug 25, 2025):
Does #1552 help?
@spockfish commented on GitHub (Aug 26, 2025):
@roderickvd Yes! I can confirm that the patch from #1552 fixes this issue as well.
Thanks!
@kingosticks commented on GitHub (Aug 26, 2025):
Was #1552 supposed to have this side effect?! From a quick glance it doesn't look related! Given I don't understand the fix, can someone explain when does librespot now release the sink? After any track finishes, or only after all the tracks in the current context finish?
@roderickvd commented on GitHub (Aug 26, 2025):
😅 it was a hunch that the queue would be cleared and playback stopped when we properly handle a disconnect event. And so it did…
@photovoltex commented on GitHub (Aug 26, 2025):
Understandably, the underlying issue is here:
https://github.com/librespot-org/librespot/blob/dev/connect/src/spirc.rs#L901
handle_disconnectearly returns on a error. Tho previously this didn't had the option to return an error, so I'm also surprised this should be resolved now.