Hytod

ExoPlayer Screen

Jul 16th, 2025
575
0
2 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.35 KB | None | 0 0
  1. this is my exoplayer screen :
  2.  
  3. @Composable
  4. fun VideoPlayerScreenRoot(
  5.     viewModel: VideoPlayerVM = koinViewModel(),
  6.     folderPath: String,
  7.     videoIndex: Int
  8. ) {
  9.     LaunchedEffect(videoIndex) {
  10.         viewModel.onAction(VideoPlayerAction.GetVideosUri(folderPath,videoIndex))
  11.     }
  12.  
  13.     val state by viewModel.videoPlayerState.collectAsStateWithLifecycle()
  14.     VideoPlayerScreen(
  15.         state = state,
  16.         player = viewModel.player,
  17.         onSeek = {
  18.             viewModel.onAction(VideoPlayerAction.OnSeek(it))
  19.         },
  20.         onRewind = {
  21.             viewModel.onAction(VideoPlayerAction.OnRewind)
  22.         },
  23.         onFastForward = {
  24.             viewModel.onAction(VideoPlayerAction.OnFastForward)
  25.         }
  26.     )
  27. }
  28.  
  29. @OptIn(UnstableApi::class)
  30. @Composable
  31. private fun VideoPlayerScreen(
  32.     state: VideoPlayerState,
  33.     player: Player,
  34.     onSeek:(position: Long) -> Unit,
  35.     onRewind:() -> Unit,
  36.     onFastForward:() -> Unit,
  37. ) {
  38.     var controlsVisible = remember { mutableStateOf(true) }
  39.  
  40.     Column(
  41.         Modifier.fillMaxSize(),
  42.         horizontalAlignment = Alignment.CenterHorizontally,
  43.         verticalArrangement = Arrangement.Center
  44.     ) {
  45.         Box(
  46.             modifier = Modifier.aspectRatio(16 / 9F).clickable {   },
  47.             contentAlignment = Alignment.Center
  48.         ) {
  49.             PlayerSurface(player,Modifier.aspectRatio(16 / 9F))
  50.             VideoControlButtons(
  51.                 isPlaying = state.isPlaying,
  52.                 isLoading = state.isLoading,
  53.                 currentPosition = state.currentPosition,
  54.                 bufferedPosition = state.bufferedPosition,
  55.                 duration = state.duration,
  56.                 onPlayPauseClick = {
  57.                     if (state.isPlaying){
  58.                         player.pause()
  59.                     } else {
  60.                         player.play()
  61.                     }
  62.                 },
  63.                 onSeek = {
  64.                     onSeek(it)
  65.                 },
  66.                 onFastForward = {
  67.                     onFastForward()
  68.                 },
  69.                 onRewind = {
  70.                     onRewind()
  71.                 },
  72.                 onToggleControlsVisibility = { controlsVisible.value = !controlsVisible.value },
  73.                 controlsVisible = controlsVisible.value
  74.             )
  75.         }
  76.        
  77.     }
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment