Search code examples
androidexoplayeraspect-ratioexoplayer2.x

How to make ExoPlayer compatible with all type video aspect ratios?


I am using ExoPlayer for playing videos in my project. The problem is whatever video I tried to play the video resolution is always in 4:3 ratio only. I tried with the following code to overcome my problem. After adding the following lines the video seems to be completely stretched.

mExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
    exoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

Solution

  • What you want to use is:

    simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
    

    This code fit's the video to the view size but maintains it's aspect ratio by cropping from the sides.