Skip to content

Instantly share code, notes, and snippets.

@AndroBrain
Last active September 2, 2024 04:53
Show Gist options
  • Save AndroBrain/26078eb04389b92fcb9b2f77cd01e6e3 to your computer and use it in GitHub Desktop.
Save AndroBrain/26078eb04389b92fcb9b2f77cd01e6e3 to your computer and use it in GitHub Desktop.
VideoControls
@Composable
fun PlayerScreen() {
...
var isPlaying by remember { mutableStateOf(true) }
Box(modifier = Modifier.fillMaxSize()) {
VideoSurface(modifier = Modifier.fillMaxSize(), exoPlayer = exoPlayer)
VideoControls(
modifier = Modifier.align(Alignment.Center),
isPlaying = isPlaying,
onClick = {
if (isPlaying) {
exoPlayer.pause()
} else {
exoPlayer.play()
}
isPlaying = !isPlaying
}
)
}
}
@Composable
fun VideoControls(
modifier: Modifier = Modifier,
isPlaying: Boolean,
onClick: () -> Unit,
) {
IconButton(
modifier = modifier,
onClick = onClick,
) {
Icon(
painter = painterResource(
id = if (isPlaying) {
R.drawable.ic_pause
} else {
R.drawable.ic_play
}
),
contentDescription = null,
tint = Color.White,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment