mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-20 02:00:57 +02:00
Reverting to have videos starting from the IO thread.
This commit is contained in:
@@ -32,6 +32,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -281,10 +282,13 @@ 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.
|
||||||
DisposableEffect(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.
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
if (controller.value == null) {
|
if (controller.value == null) {
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
uid,
|
uid,
|
||||||
@@ -348,6 +352,7 @@ fun GetVideoController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onDispose {
|
onDispose {
|
||||||
if (!keepPlaying.value) {
|
if (!keepPlaying.value) {
|
||||||
@@ -366,6 +371,7 @@ fun GetVideoController(
|
|||||||
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
|
||||||
// if the controller is not null, just continue playing what the controller was playing
|
// if the controller is not null, just continue playing what the controller was playing
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
if (controller.value == null) {
|
if (controller.value == null) {
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
uid,
|
uid,
|
||||||
@@ -398,6 +404,7 @@ 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.
|
||||||
@@ -519,7 +526,8 @@ private fun RenderVideoPlayer(
|
|||||||
.defaultMinSize(minHeight = 100.dp)
|
.defaultMinSize(minHeight = 100.dp)
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
} else {
|
} else {
|
||||||
Modifier.fillMaxWidth()
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
.defaultMinSize(minHeight = 100.dp)
|
.defaultMinSize(minHeight = 100.dp)
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user