mirror of
https://github.com/librespot-org/librespot.git
synced 2026-04-27 08:15:50 +03:00
[PR #1677] [MERGED] Emit SetQueue event #1492
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#1492
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?
📋 Pull Request Information
Original PR: https://github.com/librespot-org/librespot/pull/1677
Author: @ralph
Created: 1/22/2026
Status: ✅ Merged
Merged: 2/9/2026
Merged by: @photovoltex
Base:
dev← Head:emit-set-queue-event📝 Commits (10+)
065ca87EmitPlayer::SetQueueeventd0dd9a7Remve AddToQueue, switch to SetQueue6a07e0cAdd CHANGELOG, reformat22c7bb3EmitSetQueueonce when a track collection is added8042798Clarify wording32b0000Just callemit_set_queue_event()instead of duplicating64edaf8Use QueueTrack struct instead of(String, String)5bf1c5bMake SetQueue an opt-in event2a5f698Refactor to useConnectConfigfor opting in toSetQueueevents8fb664fUse explicit initializer value📊 Changes
6 files changed (+146 additions, -27 deletions)
View changed files
📝
CHANGELOG.md(+1 -1)📝
connect/src/spirc.rs(+56 -10)📝
connect/src/state.rs(+3 -0)📝
playback/src/player.rs(+54 -12)📝
src/main.rs(+1 -0)📝
src/player_event_handler.rs(+31 -4)📄 Description
What does this do?
This emits a new universal
Player::SetQueueevent.Background info: How is the Spotify Connect queue organised?
The Spotify connect queue basically has the following data structure:
Each Track has at least a track URI and a provider which can be
autoplay,context,queueorunavailable.autoplay: Added by Spotify to keep playingcontext: part of the current context identified bycontext_uriqueue: manually queued while a context was loadedunavailable: self explanatoryHere you can see an example of a queue:
Why is this event "universal"?
There are multiple actions that manipulate the queue in different ways. Examples:
context_uri,current_track,prev_tracks,next_tracksnext_tracksnext_tracksnext_tracksIf a GUI application wants to adjust its state when any of these actions are performed remote or local, it just needs to listen to this one universal event. The queue displayed in the GUI is always correct and always up to date.
Why does this remove AddToQueue that was just added in
87d37c3e18?AddToQueueis a special case ofSetQueue, andSetQueuecovers all cases ofAddToQueueusage. Also, it's less error prone for app developers. Say a GUI developer wants to display the current queue from Spirc, and the queue looks like this:When another track is queued, it will be placed after the currently playing track:
In this case,
AddToQueuewill be emitted for Track 1, and the GUI developer will be responsible to add it in the right position of the app's state.When yet another track (or collection of tracks, e.g. an album with 2 tracks) is queued, those will be placed after the currently playing track AND after all the other
queuetracks:In this case,
AddToQueuewill be emitted with Track 2, then with Track 3. Again, the developer of the consuming app is responsible for placing the new tracks in the right position.In contrast to this,
SetQueuealways emits the whole queue with the tracks in the right order, so the developer of the consuming app cannot place the tracks in the wrong position.Also,
AddToQueuewas never in a release, so removing it is ok imho.Are there downsides?
As we're emitting ALL THE QUEUE FIELDS \o/ with every change, we do sometimes emit more than necessary. But we have to emit
next_tracksmost of the time, and the remaining queue fields are not that large compared tonext_tracks.current_trackandcontext_uriis negligible, andprev_tracksis capped at 20 tracks.How to go from here?
I'd love to hear your input on this. Do you think a universal
SetQueueevent is a good thing? Or would you rather have more fine grained events emitting less data, e.g. one forprev_tracks, one fornext_tracksone forcurrent_trackandcurrent_track? Or should we keep the universalSetQueuefor actions that manipulate all ofnext_tracks, but keepAddToTrackwhen adding tracks to the queue, manipulating only small parts ofnext_tracks?The current approach works well for me and my reactive SwiftUI app, and makes updating the queue incredibly easy. But I'm still pretty new to this and there might be use cases that I didn't think of.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.