fix: fall back to an available device when starting playback with no active device#1007
Open
ecschoye wants to merge 1 commit into
Open
fix: fall back to an available device when starting playback with no active device#1007ecschoye wants to merge 1 commit into
ecschoye wants to merge 1 commit into
Conversation
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.
Summary
When the user starts a new playback (e.g. pressing Enter on a search result) and there is no active playback at that moment,
spotify_playersilently fails with "No playback found. Please start a new playback. Make sure there is a running Spotify device ...", even though the integratedstreamingdevice is still available. Restarting the app fixes it. This makesStartPlaybackrecover the same way startup already does.Related: #705, #710.
Root cause
PlayerRequest::StartPlaybackderives its target device solely from the current buffered playback:If the integrated device goes idle and Spotify drops it as the active device, the playback poller sets
player.playback = None(and clearsbuffered_playback). After that,device_idisNone, sostart_playbacksends no device id and the Web API targets "the currently active device", of which there is none, producing the error.initialize_playbackdoes not hit this because on startup it falls back tofind_available_device(), which explicitly appends the integrated device id (session.device_id()) under thestreamingfeature. The runtime play path had no equivalent recovery, which is why only a restart helped.Fix
In the
StartPlaybackbranch, when no device id is available from the current playback, fall back tofind_available_device(), the exact recoveryinitialize_playbackalready uses:Scoped to
StartPlaybackonly. The other requests (Resume,NextTrack,Pause, ...) legitimately operate on an existing playback and keep theirno playback foundguard.Scope / limitation
This recovers the common case where the integrated device is still registered but no longer the active device. It does not address librespot fully deregistering the device after a network blip (the librespot-side reconnection discussed in #705 / #710), which is a separate concern.
Testing
cargo build -p spotify_player— passes.cargo clippy -p spotify_player— no warnings.cargo check -p spotify_player --features streaming— passes (exercises the integrated-device branch infind_available_device).