Skip to content

Commit

Permalink
Merge pull request #3978 from element-hq/feature/bma/disableVideoAuto…
Browse files Browse the repository at this point in the history
…Play

Do not auto-play videos.
  • Loading branch information
bmarty authored Dec 2, 2024
2 parents e1be8c6 + 1ee8676 commit 4bb6c24
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ private fun ExoPlayerMediaVideoView(
localMedia: LocalMedia?,
modifier: Modifier = Modifier,
) {
val isControllerVisibleByDefault = LocalInspectionMode.current
var mediaPlayerControllerState: MediaPlayerControllerState by remember {
mutableStateOf(
MediaPlayerControllerState(
isVisible = isControllerVisibleByDefault,
isVisible = true,
isPlaying = false,
progressInMillis = 0,
durationInMillis = 0,
Expand Down Expand Up @@ -122,18 +121,16 @@ private fun ExoPlayerMediaVideoView(

override fun onTimelineChanged(timeline: Timeline, reason: Int) {
if (reason == Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) {
mediaPlayerControllerState = mediaPlayerControllerState.copy(
durationInMillis = exoPlayer.duration,
)
exoPlayer.duration.takeIf { it >= 0 }
?.let {
mediaPlayerControllerState = mediaPlayerControllerState.copy(
durationInMillis = it,
)
}
}
}
}

LaunchedEffect(Unit) {
exoPlayer.addListener(playerListener)
exoPlayer.prepare()
}

var autoHideController by remember { mutableIntStateOf(0) }

LaunchedEffect(autoHideController) {
Expand Down Expand Up @@ -238,7 +235,8 @@ private fun ExoPlayerMediaVideoView(

OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> exoPlayer.play()
Lifecycle.Event.ON_CREATE -> exoPlayer.addListener(playerListener)
Lifecycle.Event.ON_RESUME -> exoPlayer.prepare()
Lifecycle.Event.ON_PAUSE -> exoPlayer.pause()
Lifecycle.Event.ON_DESTROY -> {
exoPlayer.release()
Expand Down

0 comments on commit 4bb6c24

Please sign in to comment.