Only updates video position when the video is ready to play

This commit is contained in:
Vitor Pamplona
2024-06-07 11:44:50 -04:00
parent 7906a94ca0
commit 0e1de03db8
2 changed files with 12 additions and 6 deletions
@@ -156,7 +156,7 @@ class MultiPlayerPlaybackManager(
newPosition: PositionInfo,
reason: Int,
) {
if (mustCachePositions) {
if (mustCachePositions && player.playbackState != STATE_IDLE) {
cachedPositions.add(uri, newPosition.positionMs)
}
}
@@ -508,14 +508,20 @@ fun GetVideoController(
}
onDispose {
GlobalScope.launch(Dispatchers.Main) {
if (!keepPlaying.value) {
// Stops and releases the media.
controller.value?.let {
if (!keepPlaying.value) {
// Makes sure the variable is cleared before the task is launched
// to avoid the ON_RELEASE running before ON_PAUSE's coroutine
val toRelease = controller.value
controller.value = null
toRelease?.let {
it.pause()
GlobalScope.launch(Dispatchers.Main) {
// Stops and releases the media.
it.stop()
it.release()
Log.d("PlaybackService", "Releasing Video $videoUri ")
controller.value = null
}
}
}