Moves the video release to a thread without damaging ON_PAUSE, ON_RELEASE order.

This commit is contained in:
Vitor Pamplona 2024-06-07 11:42:15 -04:00
parent 6ce019a86a
commit 7906a94ca0

View File

@ -568,11 +568,20 @@ fun GetVideoController(
if (event == Lifecycle.Event.ON_PAUSE) {
if (!keepPlaying.value) {
// Stops and releases the media.
controller.value?.let {
// 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()
scope.launch(Dispatchers.Main) {
Log.d("PlaybackService", "Releasing Video from Pause $videoUri ")
it.stop()
it.release()
controller.value = null
Log.d("PlaybackService", "Released Video from Pause $videoUri ")
}
}
}
}