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

不羁的心 提交于 2019-11-29 01:00:25

问题


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)

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 .


回答1:


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

Using app:resize_mode in layout file this some how help but it stretches the video as mentioned in question picture,so you can solve by adding these two lines in your code.

exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
exoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);

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

playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);. 



回答2:


To maintain center crop in exo player below code worked for me:

Java code:

playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);

or you can use from xml:

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


来源:https://stackoverflow.com/questions/48988063/how-can-i-scale-video-in-exoplayer-v2-play-video-in-full-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!