Last active
July 31, 2022 11:09
-
-
Save rubenquadros/6314bc2b52e58bfe98498c93cdfcfe3b to your computer and use it in GitHub Desktop.
Simple ExoPlayer setup
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 VideoPlayer(modifier: Modifier = Modifier) { | |
val context = LocalContext.current | |
val exoPlayer = remember { | |
ExoPlayer.Builder(context).build().apply { | |
setMediaItem( | |
MediaItem.fromUri( | |
"https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" | |
) | |
) | |
prepare() | |
playWhenReady = true | |
} | |
} | |
Box(modifier = modifier) { | |
DisposableEffect(key1 = Unit) { onDispose { exoPlayer.release() } } | |
AndroidView( | |
factory = { | |
StyledPlayerView(context).apply { | |
player = exoPlayer | |
layoutParams = | |
FrameLayout.LayoutParams( | |
ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.MATCH_PARENT | |
) | |
} | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment