mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
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:
@@ -66,11 +66,21 @@ class ProgressManager @Inject constructor(
|
|||||||
private fun startSession(itemId: UUID, positionMs: Long, reportContext: PlaybackReportContext?) {
|
private fun startSession(itemId: UUID, positionMs: Long, reportContext: PlaybackReportContext?) {
|
||||||
activeItemId = itemId
|
activeItemId = itemId
|
||||||
activePlaybackReportContext = reportContext
|
activePlaybackReportContext = reportContext
|
||||||
|
val isOffline = reportContext == null
|
||||||
report(itemId, positionMs, reportContext = reportContext, isStart = true)
|
report(itemId, positionMs, reportContext = reportContext, isStart = true)
|
||||||
progressJob = scope.launch {
|
progressJob = scope.launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(5000)
|
delay(5000)
|
||||||
report(itemId, lastPositionMs, reportContext = activePlaybackReportContext, isPaused = isPaused)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user