fix: playback progress is not saved when leaving player

This commit is contained in:
Jarne Demeulemeester 2023-02-08 01:05:21 +01:00
parent 5b1830c88b
commit 9133b2a273
No known key found for this signature in database
GPG key ID: 65C6006F2032DD14

View file

@ -27,6 +27,7 @@ import dev.jdtech.jellyfin.utils.postDownloadPlaybackProgress
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
@ -166,18 +167,19 @@ constructor(
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
private fun releasePlayer() { private fun releasePlayer() {
player.let { player -> val mediaId = player.currentMediaItem?.mediaId
val position = player.currentPosition.times(10000)
GlobalScope.launch { GlobalScope.launch {
delay(1000L)
try { try {
jellyfinRepository.postPlaybackStop( jellyfinRepository.postPlaybackStop(
UUID.fromString(player.currentMediaItem?.mediaId), UUID.fromString(mediaId),
player.currentPosition.times(10000) position
) )
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e) Timber.e(e)
} }
} }
}
playWhenReady = player.playWhenReady playWhenReady = player.playWhenReady
playbackPosition = player.currentPosition playbackPosition = player.currentPosition