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

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

问题描述

我正在 Exoplayer 上从 URL 播放视频,它在调整大小时使用 resize_mode 拉伸视频,正如我在布局文件中提到的使用这个我无法保持视频的纵横比.

我想像 image2 中提到的那样在 TextureSurface 中做比例类型 CENTER_CROP 但我得到的输出为 image1

我试过下面的例子

<块引用>

exoplayer 布局代码

 

使用这一行 app:resize_mode="fill" 它适合屏幕中的视频但垂直拉伸,那么我该如何解决这个问题.

解决方案

以下两行代码帮助我以全屏模式播放视频.

在布局文件中使用 app:resize_mode 这在某种程度上有所帮助,但它会像问题图片中提到的那样拉伸视频.

尝试根据您的要求将 AspectRatioFrameLayout 更改为 FILL,FIT,ZOOM...,更改以下行对我有用.

exoVideoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);

波纹管将确保即使对于 4:3 视频也能正确保持纵横比.

exoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);

您也可以尝试在 exoplayer

中更改 VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING

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 .

解决方案

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

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

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