Fixes the access to playback state from the wrong thread

This commit is contained in:
Vitor Pamplona
2023-09-26 10:55:31 -04:00
parent ee466aa1e4
commit e3df94338f
@@ -291,8 +291,8 @@ fun GetVideoController(
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) { scope.launch(Dispatchers.IO) {
PlaybackClientController.prepareController( PlaybackClientController.prepareController(
uid, uid,
videoUri, videoUri,
@@ -338,21 +338,21 @@ fun GetVideoController(
} }
} }
} }
} else { }
controller.value?.let { } else {
if (it.playbackState == Player.STATE_IDLE || it.playbackState == Player.STATE_ENDED) { controller.value?.let {
if (it.isPlaying) { if (it.playbackState == Player.STATE_IDLE || it.playbackState == Player.STATE_ENDED) {
// There is a video playing, start this one on mute. if (it.isPlaying) {
it.volume = 0f // There is a video playing, start this one on mute.
} else { it.volume = 0f
// There is no other video playing. Use the default mute state to } else {
// decide if sound is on or not. // There is no other video playing. Use the default mute state to
it.volume = if (defaultToStart) 0f else 1f // decide if sound is on or not.
} it.volume = if (defaultToStart) 0f else 1f
it.setMediaItem(mediaItem.value)
it.prepare()
} }
it.setMediaItem(mediaItem.value)
it.prepare()
} }
} }
} }