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

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!


This can be done in XML as well if you use SimpleExoPlayerView.

Just add app:resize_mode="zoom" to keep video's aspect ratio or app:resize_mode="fill" if you don't care about aspect ratio.

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

You can remove the com.google.android.exoplayer.AspectRatioFrameLayout.

Next, put a simple FrameLayout with width and height on match_parent.

Note that the SurfaceView should stay in width and height = match_parent.

Explanation: AspectRatioFrameLayout is setting the correct height of the view according to the real video ratio (calcuclating based on width, height and pixelRatio). If you don't wan't this, Exoplayer can still display the view on a SurfaceView as they was doing before. If the SurfaceView is not @Override it will not have aspect ratio.