androidandroid-jetpack-composeexoplayer

How to remove top and bottom padding exo player in android jetpack compose?


I am try to best to remove top and bottom padding but I can't not found any solution.

My code

// Exo player
implementation("androidx.media3:media3-exoplayer:1.4.0-beta01") implementation("androidx.media3:media3-ui:1.4.0-beta01")

@Composable
fun Exoplayer(
    uri: String,
    modifier: Modifier = Modifier
) {


    val context = LocalContext.current

    val mediaItem = MediaItem.Builder()
        .setUri(uri)
        .build()
    val exoPlayer = remember(context, mediaItem) {
        ExoPlayer.Builder(context)
            .build()
            .also { exoPlayer ->
                exoPlayer.setMediaItem(mediaItem)
                exoPlayer.prepare()
                exoPlayer.playWhenReady = true
                exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
            }
    }

    val lifecycleEvent = rememberLifecycleEvent()

    LaunchedEffect(lifecycleEvent) {
        when (lifecycleEvent) {
            Lifecycle.Event.ON_STOP -> {
                exoPlayer.release()
            }

            else -> {

            }
        }
    }

    AndroidView(
        factory = {
            PlayerView(context).apply {
                player = exoPlayer
                useController = false
            }
        },
        modifier = modifier
    )
}



Exoplayer(
      previewState.themeDetail?.video ?: "",
      Modifier.fillMaxSize()
)



Solution

  • you can try adjusting the view

    PlayerView(context).apply {
        .....
        resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL
    }