Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this is my exoplayer screen :
- @Composable
- fun VideoPlayerScreenRoot(
- viewModel: VideoPlayerVM = koinViewModel(),
- folderPath: String,
- videoIndex: Int
- ) {
- LaunchedEffect(videoIndex) {
- viewModel.onAction(VideoPlayerAction.GetVideosUri(folderPath,videoIndex))
- }
- val state by viewModel.videoPlayerState.collectAsStateWithLifecycle()
- VideoPlayerScreen(
- state = state,
- player = viewModel.player,
- onSeek = {
- viewModel.onAction(VideoPlayerAction.OnSeek(it))
- },
- onRewind = {
- viewModel.onAction(VideoPlayerAction.OnRewind)
- },
- onFastForward = {
- viewModel.onAction(VideoPlayerAction.OnFastForward)
- }
- )
- }
- @OptIn(UnstableApi::class)
- @Composable
- private fun VideoPlayerScreen(
- state: VideoPlayerState,
- player: Player,
- onSeek:(position: Long) -> Unit,
- onRewind:() -> Unit,
- onFastForward:() -> Unit,
- ) {
- var controlsVisible = remember { mutableStateOf(true) }
- Column(
- Modifier.fillMaxSize(),
- horizontalAlignment = Alignment.CenterHorizontally,
- verticalArrangement = Arrangement.Center
- ) {
- Box(
- modifier = Modifier.aspectRatio(16 / 9F).clickable { },
- contentAlignment = Alignment.Center
- ) {
- PlayerSurface(player,Modifier.aspectRatio(16 / 9F))
- VideoControlButtons(
- isPlaying = state.isPlaying,
- isLoading = state.isLoading,
- currentPosition = state.currentPosition,
- bufferedPosition = state.bufferedPosition,
- duration = state.duration,
- onPlayPauseClick = {
- if (state.isPlaying){
- player.pause()
- } else {
- player.play()
- }
- },
- onSeek = {
- onSeek(it)
- },
- onFastForward = {
- onFastForward()
- },
- onRewind = {
- onRewind()
- },
- onToggleControlsVisibility = { controlsVisible.value = !controlsVisible.value },
- controlsVisible = controlsVisible.value
- )
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment