Repository navigation
Conversation
When the last track ended with nothing left to play (no repeat, no autoplay), handle_next stopped the player, which unloaded the track, so a following play command had nothing to resume until a client started something new. Spotify's own clients instead go back to the first track of the context, loaded and paused, so play starts it again. Rewind to the start of the context and load its first track paused. If the context cannot be rewound, stop as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewinding at the end of the queue loads the first track. When the end is reached by skipping a track that failed to load, and every track fails (the network is down, or the list holds only tracks that can't play), that load fails as well, `Unavailable` walks the queue to its end again, and it rewinds again, forever. The `Unavailable` handler now stops there, as it did before, and only a track that ends or a skip rewinds. `handle_next` is split: `load_next_track` moves on and loads, returning whether there was a track, so the end-of-queue policy stays with each caller. `rewind` holds the state reset `handle_stop` did, so a context that can't be rewound is reset once and warned about once. The fixture plays local files that aren't on disk, so the real player fails to load them without going online, and the new test feeds its events back until playback stops, failing if it loads more tracks than the queue holds. The rewind test drops its fixture and refill checks. The code comment and the changelog no longer claim that play did nothing after the end: a Connect client's resume reloads the track, and only `Spirc::play` and `Spirc::play_pause` did nothing. The changelog also names the changed player events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
Replace the end-of-queue rewind with a smaller fix. Playback stops at the end of the queue again, as on dev, and `handle_play` starts the current track again when playback has stopped, as a Connect client's resume already did. `Spirc::play` and `Spirc::play_pause`, which an application's own controls call, then work after the queue ends, after previous stops at the start of the first track, and after a track that failed to load stopped the queue. This keeps the player events at the end of the queue unchanged, loads nothing until play is pressed, and leaves no failed rewind to handle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When playback stops,
Spirc::playandSpirc::play_pausedo nothing, while a Connect client's resume starts it again. The common case is the end of the queue: when the last track ends, or next is pressed on it, with nothing left to play,handle_nextcallshandle_stop, which stops the player, unloads the track and rewinds the state to the first track. The device is published paused on that first track, and aresumefrom a Connect client on a stopped device loads it (Resume(_) if Stopped => load_track(true, 0)). But an application's own controls, such as media keys, go throughSpirc::play/play_pause, andhandle_playonly resumes a paused or paused-loading player. I ran into this with a headless player: after an album finished, its media keys did nothing until a Spotify app started something new.Change
handle_playnow starts the current track again when playback has stopped, withload_track(true, 0), which is what theResumearm did; that arm now just callshandle_play.handle_play_pauseplays in every state but playing and loading to play, so it takes the same path.handle_playandhandle_play_pausereturn the load'sResult, whichhandle_commandpasses on as it does forPrevandNext.Nothing else changes: playback still stops at the end of the queue, with the same player events, and nothing is loaded until play is pressed. It applies to every way playback stops, so play also starts again after
handle_prevstops at the start of the first track, or after a track that failed to load stopped the queue. With no current track,load_trackstops as before.An earlier revision of this PR instead loaded the first track paused at the end of the queue. A review found that this changed the
--oneventevents there, needed extra handling so that a queue of tracks that can't load isn't walked forever, and could still mark a context's tracks unavailable when the network was down as it ended. This version has none of that.Test
spirc::testsadds a smallSpircTaskfixture (these are the first tests inspirc.rs): an active device with a real player, which needs no connection, and a three-track context of local files that aren't on disk.play_starts_the_queue_again_once_it_has_endedlets the last track end, then callshandle_play, and in a second runhandle_play_pause, and requires the first track to be current and loading to play at 0. It fails ondev, where both do nothing.#1870 adds the same fixture to a
testsmodule at the end ofspirc.rs, and a Fixed line next to this one in CHANGELOG.md; I'll rebase whichever merges later.cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspaceare clean, and there is a changelog entry under Unreleased → Fixed.🤖 Generated with Claude Code
https://claude.ai/code/session_013zyp13aMbmU4XmKnuCPVRb