Skip to content

Fix episode resuming from the beginning after switching playback (issue #287) - #288

Merged
mapitman merged 2 commits into
mainfrom
issue-287-fix-lost-resume-position
Sep 6, 2026
Merged

mapitman merged 2 commits into
mainfrom
issue-287-fix-lost-resume-position

Conversation

@mapitman

@mapitman mapitman commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Play episode A, switch to episode B before A finishes, let B finish naturally -> A resumed from the beginning instead of where it was left off.
  • Two bugs combined to cause this:
    1. PlaybackController never explicitly saved the outgoing episode's position when switching to a different one -- the only other writers of enclosurePosition act on whatever player.currentMediaItem is at call time, which by then usually already reflects the new episode.
    2. Even once the position was saved correctly, ExoPlayer's own seamless Timeline auto-transition (the common "lookahead window" advance path from issue Android Auto / notification queue view only shows the current episode #256) never applied it -- START_POSITION_MS_EXTRA_KEY is a custom extra with no native ExoPlayer meaning, so a native auto-transition just played the new item from position 0. Only the manual playNextQueued fallback path actually seeked to it.
  • Fixes Switching to a new episode loses the previous episode's resume position #287.

Test plan

  • ./gradlew assembleDebug testDebugUnitTest lintDebug -- all pass, including two new PlaybackControllerTest regression tests.
  • Manually verified on a physical device: played episode A, switched to episode B, let B finish -- episode A now resumes from its actual last position instead of the beginning.

Switching to a different episode never explicitly saved the outgoing
episode's position -- the only other writers of enclosurePosition
(PlaybackService's periodic save loop and its on-pause save) act on
player.currentMediaItem, which by the time either fires typically
already reflects the new episode, since the switch's own setMediaItem
call updates it synchronously before the listener callback runs. The
outgoing episode's progress was lost, so Next Up auto-advancing back
to it later restarted from the beginning instead of resuming.
The lookahead window's seamless Timeline auto-transition (issue #256's
common advance path) never applied a resumed episode's saved position:
START_POSITION_MS_EXTRA_KEY is a custom extra baked into each resolved
MediaItem's metadata, and ExoPlayer's Timeline has no native concept of
a per-item start position, so a native auto-transition just played the
new current item from its own natural start (0). Only playNextQueued's
manual fallback path (used when nothing was pre-materialized) actually
seeked/set with that position. Combined with the previous commit's fix
(which ensured a switched-away-from episode's position was actually
saved at all), this closes the "resumed from the beginning" bug.
@mapitman
mapitman merged commit 224f40d into main Sep 6, 2026
1 check passed
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.

Switching to a new episode loses the previous episode's resume position

1 participant