我目前正在一个项目中使用Exoplayer,并希望在视频中实现类似于您在图像视图中看到的"CenterCrop“类型属性。基本上,它将适合于表面视图的高度,保持相同的纵横比,并裁剪出屏幕一侧的边缘。我的布局看起来像这样:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/videoPlayerContainer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="404dp">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/videoPlayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
app:controller_layout_id="@layout/empty_controls">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.google.android.exoplayer2.ui.SimpleExoPlayerView>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:background="@android:color/white"/>
</FrameLayout>
创建和启动播放器的大部分代码都是由一个同事在包装器中设置的,基本上看起来如下所示:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, loadControl);
simpleExoplayer.setSurfaceView(surfaceView);
DataSource.Factory mediaDataSourceFactory = new DefaultDataSourceFactory(context, "Agent");
MediaSource videoSource = new HlsMediaSource(uri, mediaDataSourceFactory, new Handler(), null);
simpleExoplayer.addListener(this);
simpleExoplayer.prepare(videoSource);
simpleExoplayer.setPlayWhenReady(true);
//this is supposedly used to set the scaling mode
simpleExoplayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
这段代码接受一个uri,执行一些设置并播放视频,一切都很正常。在对裁剪进行了一些研究之后,我找到了"setVideoScalingMode“,它是我在上面的代码中添加的最后一行。不幸的是,这没有任何作用。有没有人知道这应该怎么做,以及我可以调整什么来让它工作?谢谢!
发布于 2018-09-26 15:32:03
我知道这很晚才能回答。经过大量的集思广益,研究了EXOPlayer源码来实现这个功能,我自己想出来了,我所做的就是添加下面这行代码,它就像一个护身符:
mVideoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM); //This will increase video's height or width to fit with maintaining aspect ratios of video.
并删除下面提到的其他两个选项:
mExoplayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
mVideoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL)
愿这对其他人有所帮助。
https://stackoverflow.com/questions/42494705
复制相似问题