In Android, using exoplayer, how to fill surfaceview with a video that does not have the same aspect ratio with the device?

kimv picture kimv · Nov 9, 2015 · Viewed 19.4k times · Source

I have an activity that uses ExoPlayer to play a video. When I go fullscreen, unless the aspect ratio of the device is equal to that of the video, I get small black bars at the top and the bottom of the video.

This is how the layout looks :

<com.google.android.exoplayer.AspectRatioFrameLayout
    android:id="@+id/video_frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true">

    <SurfaceView android:id="@+id/surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"/>

    <View android:id="@+id/shutter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"/>

</com.google.android.exoplayer.AspectRatioFrameLayout>

I was hoping that

aspectRatioFrameLayout.setAspectRatio(mVideo.getAspectRatio());

would solve the problem, but I had no success. Is there a way to fill the screen with the video, even if part of the video is cut off from the screen?

Answer

Hien Quang Le picture Hien Quang Le · Mar 12, 2017

There is a fastest way to fill the screen with the video. Go to the SimpleExoPlayerView.java class, change the resizeMode from AspectRatioFrameLayout.RESIZE_MODE_FIT to AspectRatioFrameLayout.RESIZE_MODE_FILL. RESIZE_MODE_FILL will ignore the specified aspect ratio. Use this way if you use ExoPlayer as a module in your project.

UPDATED If you use ExoPlayer as a library, they have a method to setResizeMode(). You just set to AspectRatioFrameLayout.RESIZE_MODE_FILL in your view: simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL) That's all!