player intialization.
val exoPlayer = ExoPlayer.Builder(context).build().apply {
setMediaItem(MediaItem.fromUri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
}
and PlayerView is now replaced with StyledPlayerView
StyledPlayerView(context).apply {
player = exoPlayer
layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
Compose example below.
@Composable
fun VideoPlayer() {
val context = LocalContext.current
val exoPlayer = remember(context) {
ExoPlayer.Builder(context).build().apply {
setMediaItem(MediaItem.fromUri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
}
}
DisposableEffect(key1 = exoPlayer) {
onDispose {
exoPlayer.release()
}
}
AndroidView(modifier = Modifier
.fillMaxWidth()
.height(214.dp), factory = {
StyledPlayerView(context).apply {
player = exoPlayer
layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
})
}
SimpleExoPlayer
. All functionality has been moved toExoPlayer
instead.ExoPlayer.Builder
can be used instead ofSimpleExoPlayer.Builder
. You can find further changes here github.com/google/ExoPlayer/releases – Nigrescent