(1) 需求
因项目需要,前端需要实现https视频播放功能,能够支持全屏缩放、进度拖拽、重力感应横竖屏切换,故采用该框架。JiaoZiVideoPlayer前一版为JieCaoVideoPlayer,如果项目中不需要支持https,用上一个版本也可以。使用上也就是前一版本setup()会有返回值,当其返回true时加载缩略图即可。
(2)使用
①在buid.gradle中添加依赖
compile 'cn.jzvd:jiaozivideoplayer:6.2.4'
②xml中添加布局
<cn.jzvd.JZVideoPlayerStandard android:id="@+id/videoplayer" android:layout_width="match_parent" android:layout_height="200dp" tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteX="8dp" />这里,宽高可以设置成自己需要的。
③ 设置视频地址、缩略图、标题等
JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.videoplayer); jzVideoPlayerStandard.setUp(url , JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, "测试"); Glide.with(this).load(picUrl).into(jzVideoPlayerStandard.thumbImageView); //jzVideoPlayerStandard.thumbImageView.setBackgroundColor(Color.RED); jzVideoPlayerStandard.thumbImageView.setScaleType(ImageView.ScaleType.FIT_XY);其中,void setUp(String url, int screen, Object... objects) 第一个参数为视频地址,第二个参数为播放模式,第四个参数为标题。
public static final int SCREEN_WINDOW_LIST = 1;
public static final int SCREEN_WINDOW_FULLSCREEN = 2;
public static final int SCREEN_WINDOW_TINY = 3;
@Override public void onBackPressed() { if (JZVideoPlayer.backPress()) { return; } super.onBackPressed(); } @Override protected void onPause() { super.onPause(); JZVideoPlayer.releaseAllVideos(); }
<uses-permission android:name="android.permission.INTERNET" />⑥其他
参考:
https://www.jianshu.com/p/871d93dbc98e
https://www.jianshu.com/p/34d378bffb00
http://www.qingpingshan.com/m/view.php?aid=351076 Android JiaoZiVideoPlayer源码分析
https://www.jianshu.com/p/a5981b8d601b 拓展:Android 直播播放器+弹幕使用总结
http://blog.youkuaiyun.com/linchaolong/article/details/52805666 Android, ijkplayer增加https协议支持,编译运行ijkplayer