exoplay切换全屏,如何在ExoPlayer-V2中缩放视频-全屏播放视频

本文介绍如何使用ExoPlayer播放器正确设置视频的显示比例,避免视频在播放时出现拉伸或压缩的问题。通过调整resize_mode属性并结合特定代码实现CENTER_CROP效果,确保不同分辨率的视频都能以正确的宽高比展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

eb465e4361b574f1f8588320a90c310f.png

exoplayer layout code

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, 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);.

这是一个灵活的视频播放器。 MediaPlayer与VideoView完全分开,可以替换为其他播放器内核,如ExoPlayer和ijkPlayer。 可以完全自定义播放器视图,我们称之为控制面板。 此外,可以使用MediaPlayerManager来控制播放行为,例如全屏模式,小屏幕模式以及RecyclerView中的智能匹配模式。Features全屏,小屏播放内部支持RecyclerView中播放自定义UIAPP内全局播放静音循环播放手势操作(小窗:单指拖动,双指缩放全屏:音量,亮度,快进)ijkPlayer支持ExoPlayer支持重力感应支持PreviewDownloadDemo DownloadGetting startedbuild.gradledependencies {     // required     implementation 'org.salient.artvideoplayer:artplayer-java:0.6.0'     // Default control panel: optional     implementation 'org.salient.artvideoplayer:artplayer-ui:0.6.0'      //ijkPlayer: optional      implementation 'org.salient.artvideoplayer:artplayer-ijk:0.6.0'      implementation "org.salient.artvideoplayer:artplayer-armv7a:0.6.0"       //Other ABIs: optional      implementation "org.salient.artvideoplayer:artplayer-armv5:0.6.0"      implementation "org.salient.artvideoplayer:artplayer-x86:0.6.0"      // Other ABIs: optional (minSdk version >= 21)      implementation "org.salient.artvideoplayer:artplayer-arm64:0.6.0"      implementation "org.salient.artvideoplayer:artplayer-x86_64:0.6.0"      //ExoPlayer2 : optional      implementation "org.salient.artvideoplayer:artplayer-exo:0.6.0" }Usagejavaimport org.salient.artplayer.VideoView;VideoView videoView = new VideoView(this); videoView.setUp("http://vfx.mtime.cn/Video/2018/06/27/mp4/180627094726195356.mp4"); videoView.setControlPanel(new ControlPanel(this)); videoView.start();xmlAndroidManifest.xml <!-- required -->Activity@Overridepublic void onBackPressed() {  if (MediaPlayerManager.instance().backPress(this)) {      return;   }  super.onBackPressed(); }@Overrideprotected void onPause() {  super.onPause();  MediaPlayerManager.instance().pause(); }@Overrideprotected void onDestroy() {  super.onDestroy();  MediaPlayerMa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值