Last active
September 2, 2024 04:53
-
-
Save AndroBrain/26078eb04389b92fcb9b2f77cd01e6e3 to your computer and use it in GitHub Desktop.
VideoControls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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