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
@@ -568,11 +568,20 @@ fun GetVideoController(
if (event == Lifecycle.Event.ON_PAUSE) { if (event == Lifecycle.Event.ON_PAUSE) {
if (!keepPlaying.value) { if (!keepPlaying.value) {
// Stops and releases the media. // Stops and releases the media.
controller.value?.let { // Makes sure the variable is cleared before the task is launched
Log.d("PlaybackService", "Releasing Video from Pause $videoUri ") // to avoid the ON_RELEASE running before ON_PAUSE's coroutine
it.stop() val toRelease = controller.value
it.release() controller.value = null
controller.value = null
toRelease?.let {
it.pause()
scope.launch(Dispatchers.Main) {
Log.d("PlaybackService", "Releasing Video from Pause $videoUri ")
it.stop()
it.release()
Log.d("PlaybackService", "Released Video from Pause $videoUri ")
}
} }
} }
} }