diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt b/player/video/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt index f74ab963..27dc1dbd 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt @@ -27,6 +27,7 @@ import dev.jdtech.jellyfin.utils.postDownloadPlaybackProgress import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber @@ -166,16 +167,17 @@ constructor( @OptIn(DelicateCoroutinesApi::class) private fun releasePlayer() { - player.let { player -> - GlobalScope.launch { - try { - jellyfinRepository.postPlaybackStop( - UUID.fromString(player.currentMediaItem?.mediaId), - player.currentPosition.times(10000) - ) - } catch (e: Exception) { - Timber.e(e) - } + val mediaId = player.currentMediaItem?.mediaId + val position = player.currentPosition.times(10000) + GlobalScope.launch { + delay(1000L) + try { + jellyfinRepository.postPlaybackStop( + UUID.fromString(mediaId), + position + ) + } catch (e: Exception) { + Timber.e(e) } }