
申海最近提出了与视频相关的要求时,在GitHub上找到了一个播放器: ArtPlayer
与其他三方播放器相比安卓播放视频的软件,它更简洁,更易于扩展. 支持内核替换
GitHub地址:
使用起来有多容易?看一下代码:
首先添加这些依赖项,不要问我为什么有3

// 视频播放器
implementation 'org.salient.artvideoplayer:artplayer-java:0.7.0'
// Default control panel: optional
implementation 'org.salient.artvideoplayer:artplayer-ui:0.7.0'
//ExoPlayer2 : optional
implementation "org.salient.artvideoplayer:artplayer-exo:0.7.0"
<org.salient.artplayer.VideoView
android:id="@+id/Video_particulars_play"
android:layout_width="match_parent"
android:layout_height="match_parent" />
mVideoView = findViewById(R.id.Video_particulars_play);
// 设置视频地址和标题 并开始播放
mVideoView.setUp("http://vfx.mtime.cn/Video/2018/06/27/mp4/180627094726195356.mp4");
mVideoView.start();
然后: 在托管播放器的活动中实现以下方法

@Override
public void onBackPressed() {
if (MediaPlayerManager.instance().backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
MediaPlayerManager.instance().pause();
}
@Override
protected void onDestroy() {
super.onDestroy();
MediaPlayerManager.instance().releasePlayerAndView(this);
}
完成了安卓播放视频的软件,这很容易
...
mVideoView.setControlPanel(new ControlPanel(this));
...
mVideoView.start();
是的,只有一行代码,并且瞬间就有一个控制器.

要点了!敲黑板!!!这时,您需要将播放器核心替换为更著名的ExoPlayer
您猜几行代码,是的!是的,只要一行代码
//替换内核 在实例化之后立即调用
MediaPlayerManager.instance().setMediaPlayer(new ExoPlayer(Activity_Video_particulars.this));
以下是我经常使用的相关功能:
如果您想自己编写漂亮的进度条,则可以使用:

LogUtils.loge("当前位置:" + MediaPlayerManager.instance().getCurrentPositionWhenPlaying() +
"总时长" + MediaPlayerManager.instance().getDuration());
如果您希望它像斗音一样循环播放,可以使用:
MediaPlayerManager.instance().setLooping(true); //循环
如果您想自己编写一个播放按钮,则可以使用:
MediaPlayerManager.instance().start();
MediaPlayerManager.instance().pause();
如果您想了解更多相关信息:
1: 转到GItHub查看作者编写的源代码(例如深海)
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/bofangqi/article-270547-1.html
他不过就是能摆呼