JieCaoVideoPlayer (节操)
github 地址:JieCaoVideoPlayer
1、使用入门
依赖:implementation ‘fm.jiecao:jiecaovideoplayer:5.5.2’
2、布局
<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
android:id="@+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="200dp"/>
3、代码使用
//禁止视频缓存
JCVideoPlayer.SAVE_PROGRESS = false;
//加载视频地址
courseDetailsJCVideo.setUp(uri,JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL);
//加载视频封面
Glide.with(this).load(uri).into(courseDetailsJCVideo.thumbImageView);
第二个参数为显示视频的方式
public static final int SCREEN_LAYOUT_NORMAL = 0; //正常模式
public static final int SCREEN_LAYOUT_LIST = 1; //列表模式
public static final int SCREEN_WINDOW_FULLSCREEN = 2; //全屏模式
public static final int SCREEN_WINDOW_TINY = 3; //小屏模式
4、拦截事件
Activity中:
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
Fragment中:
@Override
public void onResume() {
super.onResume();
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
if (JCVideoPlayer.backPress()) {
return true;
}
return false;
}
return false;
}
});
}
5、回收资源
@Override
protected void onPause() {
super.onPause();
JCVideoPlayer.releaseAllVideos();
}
6、AndroidManifest 的设置
<activity
android:name="yourActivityName"
android:configChanges="orientation|screenSize|keyboardHidden"
android:hardwareAccelerated="true"
android:screenOrientation="portrait" />
以上为JieCaoVideoPlayer的简单使用,参考地址https://blog.youkuaiyun.com/yaya_xiong/article/details/75213346
7、JieCaoVideoPlayer方法
继承JCVideoPlayerStandard,重写方法;
开始播放:
@Override
public void onPrepared() {
super.onPrepared();
Log.e(TAG, "onPrepared: 开始播放");
}
播放完成:
@Override
public void onAutoCompletion() {
super.onAutoCompletion();
Log.e(TAG, "onAutoCompletion: 播放完成");
}