如何在ExoPlayer-V2中缩放视频-全屏播放视频 [英] How can I scale video in ExoPlayer-V2 - Play Video In Full Screen

查看:1132
本文介绍了如何在ExoPlayer-V2中缩放视频-全屏播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Exoplayer上的URL播放视频,正如我在布局文件中所提到的那样,它使用resize_mode在缩放/打开时拉伸了视频,但我无法保持视频的宽高比.

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.

我想要像 image2 中提到的那样在TextureSurface中进行缩放类型CENTER_CROP,但是我得到的输出为 image1

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

我尝试了以下示例

Exoplayer演示示例

我的输出(图1)和预期的输出(图2)

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

exoplayer布局代码

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" />

通过这行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 .

推荐答案

以下两行内容帮助我在全屏模式下播放视频.

在布局文件中使用app:resize_mode会有所帮助,但它会像问题图片中所示那样拉伸视频,因此您可以通过在代码中添加这两行来解决问题.

Using app:resize_mode in layout file this somehow help but it stretches the video as mentioned in the 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);

黑线将确保即使对于4:3的视频也可以正确地保持宽高比.

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

playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);. 

这篇关于如何在ExoPlayer-V2中缩放视频-全屏播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆