Zach Bublil
Zach Bublil

Reputation: 867

ExoPlayer video not cropping and fit

I use ExoPlayer library for loading videos from my server and I want to scale and crop the videos to keep their aspect ratio. The videos playing fine and everything are fine even when I change the volume of the video. I tried to use the setVideoScalingMode function on the SimpleExoPlayer and passed:

C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING

Nothing happens and I also tried to change the resize attribute to fill/fit. Still no scaling and cropping.

Upvotes: 3

Views: 8464

Answers (3)

Kaaveh Mohamedi
Kaaveh Mohamedi

Reputation: 1805

In compose you can set like this:

    AndroidView(
        factory = { mContext ->
            StyledPlayerView(mContext).apply {
                resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
                player = exo
            }
        },
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Black)
    )

Upvotes: 0

Arun NS
Arun NS

Reputation: 2110

Java or Kotlin

playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);

XML

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/playerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:resize_mode="zoom"/>

Upvotes: 3

Zach Bublil
Zach Bublil

Reputation: 867

After a lot of researchers all over the internet and after a lot of time debugging the exoplayer library code in order to understand why the scaling doesn't work. I found another option for the "resizeMode" attribute via code instead of the xml option which is "RESIZE_MODE_ZOOM" and it cropped the video to maintain the ratio. Hope it will someone who will encounter the problem.

Upvotes: 10

Related Questions