fix(player): persist previous item progress before updating position snapshot

Reorder the position/duration snapshot in ProgressManager.bind() so
stopSession() reads the previous item's last-known position instead
of the next item's seek target. Fixes the offline Room database
being written with 0% progress on item transitions.
This commit is contained in:
2026-07-05 08:02:28 +00:00
parent a2121afc2d
commit f4d2fdd3f7

View File

@@ -43,8 +43,6 @@ class ProgressManager @Inject constructor(
combine(playbackState, progress, metadata) { state, prog, meta ->
Triple(state, prog, meta)
}.collect { (state, prog, meta) ->
lastPositionMs = prog.positionMs
lastDurationMs = prog.durationMs
isPaused = !state.isPlaying
val mediaId = meta.mediaId?.let { runCatching { UUID.fromString(it) }.getOrNull() }
val nextPlaybackReportContext = meta.playbackReportContext
@@ -53,6 +51,9 @@ class ProgressManager @Inject constructor(
stopSession()
}
lastPositionMs = prog.positionMs
lastDurationMs = prog.durationMs
if (activeItemId == null && mediaId != null && !state.isEnded) {
startSession(mediaId, prog.positionMs, nextPlaybackReportContext)
} else if (activeItemId == mediaId) {