Stop queueing the same episode twice in MockEpisodePlayer by rootkiller6788 · Pull Request #1731 · android/compose-samples · GitHub
Skip to content

Stop queueing the same episode twice in MockEpisodePlayer - #1731

Open
rootkiller6788 wants to merge 2 commits into
android:mainfrom
rootkiller6788:fix-play-list-queue-duplicates
Open

rootkiller6788 wants to merge 2 commits into
android:mainfrom
rootkiller6788:fix-play-list-queue-duplicates

Conversation

@rootkiller6788

Copy link
Copy Markdown

Playing a whole episode list (podcast details, latest episodes, queue screens on Wear) was leaving the same episode in the queue twice, so it came back around and played again at the end.

Two problems in MockEpisodePlayer.play(list):

  • the remaining queue was rebuilt inside a map() over the new episodes and stored in a captured var, so every element overwrote it and only the removals for the last episode happened to survive. An episode that was both queued and part of the new list stayed in the queue.
  • the currently playing episode was appended without checking whether the new list already contains it. LatestEpisodeViewModel/PodcastDetailsViewModel/QueueViewModel all set currentEpisode = episodes[0] right before calling play(episodes), so that episode was queued a second time.

I now compute the leftovers once with filterNot, and only add the playing episode back when the new list does not contain it. Two tests cover both cases - I ran them against the current code first and they fail with the duplicate entry, then pass with the change. All 11 tests in MockEpisodePlayerTest are green.

Note: I have no Android SDK on this machine, so I could not run the full Jetcaster build. I compiled MockEpisodePlayer and its test with a plain Kotlin/JVM setup (kotlinc 2.2.20 + kotlinx-coroutines-test) instead.

play(listOf(...)) rebuilt the queue inside a map() over the new episodes
and used a captured var to remember the leftovers, so the leftover list
was overwritten once per episode: only the removals for the very last
episode of the new list survived. Episodes that were both in the new
list and in the queue ended up in the queue twice.

The currently playing episode was also appended unconditionally. The
callers (LatestEpisodeViewModel/PodcastDetailsViewModel/QueueViewModel)
set currentEpisode to the first episode of the list right before calling
play(list), so that episode was queued a second time and played again at
the end of the queue.

Build the leftover list once with filterNot and skip the playing episode
when the new list already contains it.
Both cases come from the Wear app: playing a whole episode list twice in
a row used to leave the first episode in the queue again, and an episode
that was already queued showed up twice after being re-queued.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review October 15, 2026 03:27
@rootkiller6788
rootkiller6788 requested a review from a team as a code owner October 15, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant