feat(player): persist offline media progress periodically during playback

Add a periodic call to updateWatchProgress in the 5-second progress loop when playing offline media (playbackReportContext == null).

Previously, offline media progress was only written to the Room database on session stop/release. This meant that if playback was interrupted (crash, force-kill) the persisted position would be lost.

Now, the Room offline cache is updated every 5 seconds during offline playback, matching the existing scrobble cadence for online streaming.
This commit is contained in:
2026-07-09 16:12:40 +00:00
parent f4d2fdd3f7
commit 5720d4e45b

View File

@@ -66,11 +66,21 @@ class ProgressManager @Inject constructor(
private fun startSession(itemId: UUID, positionMs: Long, reportContext: PlaybackReportContext?) {
activeItemId = itemId
activePlaybackReportContext = reportContext
val isOffline = reportContext == null
report(itemId, positionMs, reportContext = reportContext, isStart = true)
progressJob = scope.launch {
while (isActive) {
delay(5000)
report(itemId, lastPositionMs, reportContext = activePlaybackReportContext, isPaused = isPaused)
if (isOffline) {
scope.launch(Dispatchers.IO) {
try {
mediaMetadataUpdater.updateWatchProgress(itemId, lastPositionMs, lastDurationMs)
} catch (e: Exception) {
Timber.tag(TAG).e(e, "Local cache update failed")
}
}
}
}
}
}