隐藏自带按钮
第一篇
中讲述了如何快速上手ExoPlayer,所用到的显示控件是StyledPlayerView。在默认情况下,StyledPlayerView是会显示自带的控制按钮和进度条的。
隐藏它们很简单,只需把use_controller设置成false即可。
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:use_controller="false"/>
自定义布局
隐藏了StyledPlayerView自带的按钮及进度条后,我们就可以自己来设计控制套件了,布局如下。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="false"/>
<ImageView
android:id="@+id/image_play"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_play"
android:visibility="visible"
android:layout_centerInParent="true"/>
</RelativeLayout>
为显示控件添加点击事件监听。注意StyledPlayerView本身是不会接收任何点击监听事件的,即便给StyledPlayerView调用setOnClickedListener也是无效的。
mVideoView.getVideoSurfaceView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mPlayer.isPlaying()){
mPlayer.pause();
mPlayImage.setVisibility(View.VISIBLE);
}else{
if(!mPlayer.isLoading()){
MediaItem mediaItem = MediaItem.fromUri("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
mPlayer.setMediaItem(mediaItem);
mPlayer.prepare();
}
mPlayer.play();
mPlayImage.setVisibility(View.INVISIBLE);
}
}
});
最后看看结果(呃…好像比官方的还…),进度条、视频切换按钮等也是一样的。
版权声明:本文为PYJTRK原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。