Starting videos from Main, but in a thread.
This commit is contained in:
@@ -301,6 +301,7 @@ fun GetVideoController(
|
||||
nostrUriCallback,
|
||||
context
|
||||
) {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
// REQUIRED TO BE RUN IN THE MAIN THREAD
|
||||
|
||||
// checks again because of race conditions.
|
||||
@@ -343,8 +344,10 @@ fun GetVideoController(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
controller.value?.let {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
if (it.playbackState == Player.STATE_IDLE || it.playbackState == Player.STATE_ENDED) {
|
||||
if (it.isPlaying) {
|
||||
// There is a video playing, start this one on mute.
|
||||
@@ -360,6 +363,7 @@ fun GetVideoController(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onDispose {
|
||||
if (!keepPlaying.value) {
|
||||
@@ -386,6 +390,7 @@ fun GetVideoController(
|
||||
nostrUriCallback,
|
||||
context
|
||||
) {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
// REQUIRED TO BE RUN IN THE MAIN THREAD
|
||||
|
||||
// checks again to make sure no other thread has created a controller.
|
||||
@@ -399,7 +404,8 @@ fun GetVideoController(
|
||||
} else {
|
||||
// There is no other video playing. Use the default mute state to
|
||||
// decide if sound is on or not.
|
||||
controller.value?.volume = if (defaultToStart) 0f else 1f
|
||||
controller.value?.volume =
|
||||
if (defaultToStart) 0f else 1f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +420,7 @@ fun GetVideoController(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
if (!keepPlaying.value) {
|
||||
// Stops and releases the media.
|
||||
|
||||
Reference in New Issue
Block a user