Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scale video in ExoPlayer-V2 - Play Video In Full Screen

I am playing video from URL on Exoplayer, it stretching the video on resizing/on using resize_mode as I have mentioned in layout file using this I am not able to maintain the aspect ratio of video.

I want to do scale type CENTER_CROP like we do in TextureSurface as mentioned in image2 but I am getting output as image1

I have tried following example

Exoplayer Demo Example

My Output (Img 1) and Expected Output (Img 2)

enter image description here

exoplayer layout code

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

With this line app:resize_mode="fill" it fit the video in screen but stretch vertically, So how can I solve this .

like image 924
Sagar Avatar asked Feb 26 '18 12:02

Sagar


People also ask

Can we play YouTube video in ExoPlayer Android?

ExoPlayer is the video player running in Android YouTube, Netflix, Amazon media player for Prime, HotStar, and many other popular and robust apps. Good documentation and tutorials. It's free!

How do I change video quality on ExoPlayer?

ExoPlayer provides a way of setting a max bitrate using DefaultTrackSelector#Parameters . You can use setMaxVideoBitrate or setMaxVideoSize to limit the max bitrate. In this way, it works in many cases.


1 Answers

Following two lines helped me to play video in full-screen mode.

Using app:resize_mode in layout file this somehow help but it stretches the video as mentioned in the question picture.

<com.google.android.exoplayer2.ui.PlayerView       android:layout_width="match_parent"       app:resize_mode="...."       android:layout_height="match_parent" /> 

Try changing AspectRatioFrameLayout to FILL,FIT,ZOOM... as per yout requirement, changing below line worked for me.

exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL); 

Bellow line will ensure that aspect ratio is correctly maintained even for 4:3 videos.

exoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT); 

Also you can try changing VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING in exoplayer

like image 146
Sagar Avatar answered Sep 22 '22 12:09

Sagar