Created
June 2, 2023 11:03
-
-
Save victorbrndls/6603bd3e72df11e0db8e13bca183fbb2 to your computer and use it in GitHub Desktop.
This file contains 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 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