Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Created June 2, 2023 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorbrndls/6603bd3e72df11e0db8e13bca183fbb2 to your computer and use it in GitHub Desktop.
Save victorbrndls/6603bd3e72df11e0db8e13bca183fbb2 to your computer and use it in GitHub Desktop.
@Composable
fun VideoView(
onVideoLoaded: () -> Unit,
onVideoEnded: () -> Unit,
) {
val context = LocalContext.current
val lifecycle = LocalLifecycleOwner.current.lifecycle
val exoPlayer = ExoPlayer.Builder(context)
.build()
.also { exoPlayer ->
val mediaItem = MediaItem.Builder()
.setUri(RawResourceDataSource.buildRawResourceUri(...))
.build()
exoPlayer.setMediaItem(mediaItem)
exoPlayer.repeatMode = Player.REPEAT_MODE_ONE
exoPlayer.prepare()
}
DisposableEffect(
AndroidView(
factory = {
StyledPlayerView(context).apply {
player = exoPlayer
}
},
modifier = Modifier.aspectRatio(0.764f)
)
) {
onDispose { exoPlayer.release() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment