mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-08 21:42:46 +02:00
Fixes video keep playing bug when pressing the bottom bar twice.
This commit is contained in:
@@ -282,12 +282,14 @@ fun GetVideoController(
|
|||||||
UUID.randomUUID().toString()
|
UUID.randomUUID().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
// Prepares a VideoPlayer from the foreground service.
|
// Prepares a VideoPlayer from the foreground service.
|
||||||
LaunchedEffect(key1 = videoUri) {
|
DisposableEffect(key1 = videoUri) {
|
||||||
// If it is not null, the user might have come back from a playing video, like clicking on
|
// If it is not null, the user might have come back from a playing video, like clicking on
|
||||||
// the notification of the video player.
|
// the notification of the video player.
|
||||||
if (controller.value == null) {
|
if (controller.value == null) {
|
||||||
launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
uid,
|
uid,
|
||||||
videoUri,
|
videoUri,
|
||||||
@@ -351,12 +353,20 @@ fun GetVideoController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDispose {
|
||||||
|
if (!keepPlaying.value) {
|
||||||
|
// Stops and releases the media.
|
||||||
|
controller.value?.stop()
|
||||||
|
controller.value?.release()
|
||||||
|
controller.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// User pauses and resumes the app. What to do with videos?
|
// User pauses and resumes the app. What to do with videos?
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
val lifeCycleOwner = LocalLifecycleOwner.current
|
val lifeCycleOwner = LocalLifecycleOwner.current
|
||||||
DisposableEffect(key1 = videoUri) {
|
DisposableEffect(key1 = lifeCycleOwner) {
|
||||||
val observer = LifecycleEventObserver { _, event ->
|
val observer = LifecycleEventObserver { _, event ->
|
||||||
if (event == Lifecycle.Event.ON_RESUME) {
|
if (event == Lifecycle.Event.ON_RESUME) {
|
||||||
// if the controller is null, restarts the controller with a new one
|
// if the controller is null, restarts the controller with a new one
|
||||||
@@ -364,7 +374,7 @@ fun GetVideoController(
|
|||||||
if (controller.value == null) {
|
if (controller.value == null) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
UUID.randomUUID().toString(),
|
uid,
|
||||||
videoUri,
|
videoUri,
|
||||||
nostrUriCallback,
|
nostrUriCallback,
|
||||||
context
|
context
|
||||||
@@ -408,13 +418,6 @@ fun GetVideoController(
|
|||||||
lifeCycleOwner.lifecycle.addObserver(observer)
|
lifeCycleOwner.lifecycle.addObserver(observer)
|
||||||
onDispose {
|
onDispose {
|
||||||
lifeCycleOwner.lifecycle.removeObserver(observer)
|
lifeCycleOwner.lifecycle.removeObserver(observer)
|
||||||
|
|
||||||
if (!keepPlaying.value) {
|
|
||||||
// Stops and releases the media.
|
|
||||||
controller.value?.stop()
|
|
||||||
controller.value?.release()
|
|
||||||
controller.value = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user