Move current song to front of queue when shuffle is enabled#33
Open
lostf1sh wants to merge 1 commit into
Open
Conversation
Toggling shuffle mid-playback anchored the current song at its old index, shuffling random songs into the slots before the playhead. Forward playback never reached those songs and prev walked into tracks that were never played. Shuffle-on now places the current song at index 0 (matching every other shuffle entry point) and applies the new order by removing the items before the playing item and replacing the tail — two player calls for any queue size, without interrupting playback. The persistent-shuffle branch of playSongs had the same flaw and now also starts the shuffled queue at zero. Fixes #32
3f3eb4f to
624243c
Compare
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.
Fixes #32
Root cause
Toggling shuffle mid-playback built the shuffled queue with the current song anchored at its old index (
buildAnchoredShuffleQueueSuspendingwithoutstartAtZero). Playing at index 3 meant three random songs were shuffled into slots 0–2 — behind the playhead. Forward playback never reached them, and pressing prev walked into songs that were never actually played, exactly as reported. Every other shuffle entry point (Home, playlist, artist, daily mix) already passesstartAtZero = true; only two paths were outliers.Changes
PlaybackStateHolder.toggleShuffle(enable path): builds the shuffled queue withstartAtZero = trueand applies it via a newreplacePlayerQueueWithCurrentFirst()helper — removes the items before the playing item, then replaces the tail with the shuffled remainder. Two player calls regardless of queue size, no playback interruption. This also replaces the oldBULK_REPLACE_THRESHOLDbranching for this path (the small-queue variant issued onemoveMediaItemIPC per song). The fallback full-replace and the unshuffle path (restore original order at original index) are unchanged.PlayerViewModel.playSongs(persistent-shuffle branch): had the same stranded-songs flaw when tapping a song mid-list with persistent shuffle on; now also starts the shuffled queue at zero.PlaybackStateHolderTest: regression test driving the realtoggleShuffleagainst a stateful fake player, asserting the playing song moves to index 0, keeps playing, and no songs are lost.Testing
./gradlew :app:compileDebugKotlin— passes./gradlew :app:testDebugUnitTest(full suite, incl. new regression test) — passes