本文主要是介绍饺子播放器、IjkVideoView播放器的简单使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
饺子播放器
一、加入依赖
implementation 'cn.jzvd:jiaozivideoplayer:6.2.4'
二、视频横竖屏切换 需要在清单文件中设置属性
<activityandroid:name=".JiaoZiplayerActivity"android:configChanges="orientation|screenSize|keyboardHidden"android:screenOrientation="portrait" />
三、播放
private void initView() {jps.setUp("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL,"狮子王");jps.thumbImageView.setImageURI(Uri.parse("https://images0.cnblogs.com/blog/651487/201501/281616176915467.jpg"));new Thread(new Runnable() {@Overridepublic void run() {final Bitmap bitmap = createVideoThumbnail("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", jps.thumbImageView.getMaxWidth(),jps.thumbImageView.getMaxHeight());runOnUiThread(new Runnable() {@Overridepublic void run() {jps.thumbImageView.setImageBitmap(bitmap);}});}}).start();jps.widthRatio = 4;jps.heightRatio = 3;//设置全屏播放JZVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; //横向JZVideoPlayer.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; //纵向}
四、如果需要视频封面 可以封装工具类 截取特定帧
//获取视频的第一帧作为视频的缩略图(网络视频):@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)private Bitmap createVideoThumbnail(String url, int width, int height) {Bitmap bitmap = null;MediaMetadataRetriever retriever = new MediaMetadataRetriever();int kind = MediaStore.Video.Thumbnails.MINI_KIND;try {if (Build.VERSION.SDK_INT >= 14) {retriever.setDataSource(url, new HashMap<String, String>());} else {retriever.setDataSource(url);}bitmap = retriever.getFrameAtTime();} catch (IllegalArgumentException ex) {// 假设这是一个损坏的视频文件} catch (RuntimeException ex) {//假设这是一个损坏的视频文件} finally {try {retriever.release();} catch (RuntimeException ex) {// 清理时忽略故障}}if (kind == MediaStore.Images.Thumbnails.MICRO_KIND && bitmap != null) {bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);}return bitmap;}
五、健壮性 及时清理
@Overridepublic void onBackPressed() {if (JZVideoPlayerStandard.backPress()) {return;}super.onBackPressed();}@Overrideprotected void onPause() {super.onPause();JZVideoPlayerStandard.releaseAllVideos();}
IjkVideoView播放器
一、加入依赖
implementation 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.5'
``
**二、写入代码 有需求可以自行更改**
```javascriptView rootView = getLayoutInflater().from(this).inflate(R.layout.simple_player_view_player, null);setContentView(rootView);playerView = new PlayerView(this).setScaleType(PlayStateParams.fitparent).setPlaySource("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4").setTitle("标题").startPlay();
这篇关于饺子播放器、IjkVideoView播放器的简单使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!