kopia lustrzana https://github.com/vitorpamplona/amethyst
Makes sure only one pepare is run for each video view.
rodzic
ef363457e8
commit
8cf04967c3
|
@ -115,6 +115,7 @@ import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
public val DEFAULT_MUTED_SETTING = mutableStateOf(true)
|
public val DEFAULT_MUTED_SETTING = mutableStateOf(true)
|
||||||
|
@ -394,6 +395,8 @@ fun GetVideoController(
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val onlyOnePreparing = AtomicBoolean()
|
||||||
|
|
||||||
val controller =
|
val controller =
|
||||||
remember(videoUri) {
|
remember(videoUri) {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
|
@ -421,6 +424,8 @@ fun GetVideoController(
|
||||||
// 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) {
|
||||||
|
// If there is a connection, don't wait.
|
||||||
|
if (!onlyOnePreparing.getAndSet(true)) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Log.d("PlaybackService", "Preparing Video $videoUri ")
|
Log.d("PlaybackService", "Preparing Video $videoUri ")
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
|
@ -446,6 +451,9 @@ fun GetVideoController(
|
||||||
it.prepare()
|
it.prepare()
|
||||||
|
|
||||||
controller.value = it
|
controller.value = it
|
||||||
|
|
||||||
|
onlyOnePreparing.getAndSet(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -454,6 +462,8 @@ fun GetVideoController(
|
||||||
controller.value?.let {
|
controller.value?.let {
|
||||||
scope.launch(Dispatchers.Main) {
|
scope.launch(Dispatchers.Main) {
|
||||||
if (it.playbackState == Player.STATE_IDLE || it.playbackState == Player.STATE_ENDED) {
|
if (it.playbackState == Player.STATE_IDLE || it.playbackState == Player.STATE_ENDED) {
|
||||||
|
Log.d("PlaybackService", "Preparing Existing Video $videoUri ")
|
||||||
|
|
||||||
if (it.isPlaying) {
|
if (it.isPlaying) {
|
||||||
// There is a video playing, start this one on mute.
|
// There is a video playing, start this one on mute.
|
||||||
it.volume = 0f
|
it.volume = 0f
|
||||||
|
@ -497,6 +507,7 @@ fun GetVideoController(
|
||||||
// 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
|
||||||
if (controller.value == null) {
|
if (controller.value == null) {
|
||||||
|
if (!onlyOnePreparing.getAndSet(true)) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Log.d("PlaybackService", "Preparing Video from Resume $videoUri ")
|
Log.d("PlaybackService", "Preparing Video from Resume $videoUri ")
|
||||||
PlaybackClientController.prepareController(
|
PlaybackClientController.prepareController(
|
||||||
|
@ -523,6 +534,8 @@ fun GetVideoController(
|
||||||
it.prepare()
|
it.prepare()
|
||||||
|
|
||||||
controller.value = it
|
controller.value = it
|
||||||
|
onlyOnePreparing.getAndSet(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue