JieCaoVideoPlayer是一个非常好用的视频播放控件
特点
1.可以完全自定义UI和任何功能
2.一行代码切换播放引擎,支持的视频格式和协议取决于播放引擎,android.media.MediaPlayer ijkplayer
3.完美检测列表滑动
4.可实现全屏播放,小窗播放
5.能在ListView、ViewPager和ListView、ViewPager和Fragment等多重嵌套模式下全屏工作
6.可以在加载、暂停、播放等各种状态中正常进入全屏和退出全屏
7.多种视频适配屏幕的方式,可铺满全屏,可以全屏剪裁
8.重力感应自动进入全屏
9.全屏后手势修改进度和音量
10.Home键退出界面暂停播放,返回界面继续播放
11.WebView嵌套本地视频控件
12.demo中添加视频缓存的例子
github地址:https://github.com/lipangit/JiaoZiVideoPlayer
使用方式
1.添加依赖
implementation 'cn.jzvd:jiaozivideoplayer:6.4.1'
2.添加布局
<cn.jzvd.JzvdStd
android:id="@+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="200dp"/>
3.设置视频的地址,缩略图片以及标题
mVideoplayer.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4"
, "饺子快长大" , Jzvd.SCREEN_WINDOW_NORMAL);
Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(mVideoplayer.thumbImageView);
4.在Activity(Fragment)中的onPause()方法中调用Jzvd.releaseAllVideos()
@Override
public void onBackPressed() {
if (Jzvd.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
Jzvd.releaseAllVideos();
}
5.在AndroidManifest.xml要进行相对应的配置
<uses-permission android:name="android.permission.INTERNET"/>
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait"
>
</activity>
全屏播放视频
JzvdStd.startFullscreen(this, JzvdStd.class, VideoConstant.videoUrlList[6], "饺子辛苦了");
在列表中播放视频
1.在ListView中播放视频
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Jzvd.onScrollReleaseAllVideos(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
});
2.在RecyclerView中播放视频
recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
}
@Override
public void onChildViewDetachedFromWindow(View view) {
Jzvd jzvd = view.findViewById(R.id.videoplayer);
if (jzvd != null && jzvd.jzDataSource.containsTheUrl(JZMediaManager.getCurrentUrl())) {
Jzvd currentJzvd = JzvdMgr.getCurrentJzvd();
if (currentJzvd != null && currentJzvd.currentScreen != Jzvd.SCREEN_WINDOW_FULLSCREEN) {
Jzvd.releaseAllVideos();
}
}
}
});
开启小窗播放视频
mJzvdStd.startWindowTiny();
列表滑出的开启小窗播放视频
ListView
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Jzvd.onScrollAutoTiny(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
});
RecyclerView
recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
Jzvd.onChildViewAttachedToWindow(view, R.id.videoplayer);
}
@Override
public void onChildViewDetachedFromWindow(View view) {
Jzvd.onChildViewDetachedFromWindow(view);
}
});
总结
以上的布局基本就完成了视频播放的功能,具体页面就不贴出来了,如果有需要,可以去我的csdn和github进行下载。
下载
CSDN
https://download.csdn.net/download/wen_haha/10877816
Github