Moves the video release to a thread without damaging ON_PAUSE, ON_RELEASE order.
This commit is contained in:
@@ -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
|
||||||
|
// 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 ")
|
Log.d("PlaybackService", "Releasing Video from Pause $videoUri ")
|
||||||
it.stop()
|
it.stop()
|
||||||
it.release()
|
it.release()
|
||||||
controller.value = null
|
Log.d("PlaybackService", "Released Video from Pause $videoUri ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user