I'm building a video player using the latest media3 Exoplayer, using Jetpack Compose:
The issue I am facing is that if I set the PlayerView to fullscreen
AndroidView(modifier = Modifier.fillMaxSize(),...)
the video will be stretched upon first opening it (or navigating to it via next()/previous()):
However, if I flip the orientation it displays correctly, and then displays correctly when I flip it back:
This is how I ultimately want it to look. My Code:
Scaffold(
topBar = { MyAppBar() },
content = { innerPadding ->
viewModel.openMediaFile(mediaFile)
Box(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
.background(MyTheme.colors.background),
contentAlignment = Alignment.Center
) {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
PlayerView(context).apply {
player = viewModel.player
artworkDisplayMode = PlayerView.ARTWORK_DISPLAY_MODE_FIT
artworkPlaceHolder?.let { defaultArtwork = it }
}
}
)
}
},
)
If I don't set
AndroidView(modifier = Modifier.fillMaxSize(),...)
it just looks bad, as I would like the overlay to fill the entire screen.
What I've tried:
artworkDisplayMode = PlayerView.ARTWORK_DISPLAY_MODE_FITin thePlayerViewblock in Compose,- instantiating the player with
ExoPlayer.Builder(context)
.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT)
.build()
- using
layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
What I'm trying to achieve is a full screen layout with a fitted video.



Since you are using a viewModel to store the player, you are most likely preserving the same player between different videos.
Based on the AndroidView docs you can use the update method to fix this:
Result on first load: