From 5720d4e45b26eea0c94f903fc06b93e7bba8581b Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Thu, 9 Jul 2026 16:12:40 +0000 Subject: [PATCH] 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. --- .../purefin/core/player/manager/ProgressManager.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt b/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt index a367af4d..c2a0bc0c 100644 --- a/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt +++ b/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt @@ -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") + } + } + } } } }