一、环境搭建
? ? ? ? 1、JZ主依赖,版本7.7
implementation 'cn.jzvd:jiaozivideoplayer:7.7.0'
?2、如果需要切换解码内核则需导入别的依赖
//阿里内核
implementation 'com.aliyun.sdk.android:AliyunPlayer:4.5.0-full'
implementation 'com.alivc.conan:AlivcConan:0.9.5'
//IJKPlayer解析
implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
//EXo内核
implementation 'com.google.android.exoplayer:exoplayer:2.12.1'
注意:阿里内核必须依赖AlivcConan否则会报如下错误
java.lang.UnsatisfiedLinkError: dlopen failed: library "libalivc_conan.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
at java.lang.System.loadLibrary(System.java:1664)
at com.aliyun.player.nativeclass.NativePlayerBase.<clinit>(NativePlayerBase.java:49)
at com.aliyun.player.ApsaraVideoPlayer.createAlivcMediaPlayer(ApsaraVideoPlayer.java:28)
at com.aliyun.player.AVPBase.<init>(AVPBase.java:473)
at com.aliyun.player.ApsaraVideoPlayer.<init>(ApsaraVideoPlayer.java:22)
at com.aliyun.player.AliPlayerFactory.createAliPlayer(AliPlayerFactory.java:50)
at com.aliyun.player.AliPlayerFactory.createAliPlayer(AliPlayerFactory.java:39)
at com.odoo.exoplayer.custome.JZMediaAliyun.lambda$prepare$1$JZMediaAliyun(JZMediaAliyun.java:90)
at com.odoo.exoplayer.custome.-$$Lambda$JZMediaAliyun$5wpN2jnP_QnEF2zaAUClmoemK3Q.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
二、常用一些设置
1、设置切换内核,我这里是阿里云的内核
mJzvdStd.setMediaInterface(JZMediaAliyun::class.java)
2、设置视频封面,这里源代码已经直接提供了控件,直接加载图片地址就好
mJzvdStd.posterImageView
3、修改进度条,修改UI尽量在changeUiToNormal中完成,但有的多状态的可能不行
override fun changeUiToNormal() {
super.changeUiToNormal()
LogUtil.d("changeUiToNormal")
//修改进度条
progressBar.thumb=context.getDrawable(R.drawable.seek_bar_thumb)
}
? ? 4、修改播放、暂停、重播样式
override fun updateStartImage() {
if (state == STATE_PLAYING) {
startButton.visibility = VISIBLE
//暂停样式
startButton.setImageResource(R.drawable.jz_click_pause_selector)
replayTextView.visibility = GONE
} else if (state == STATE_ERROR) {
startButton.visibility = INVISIBLE
replayTextView.visibility = GONE
} else if (state == STATE_AUTO_COMPLETE) {
startButton.visibility = VISIBLE
//重新播放样式
startButton.setImageResource(R.drawable.jz_click_replay_selector)
replayTextView.visibility = VISIBLE
} else {
//播放样式
startButton.setImageResource(R.mipmap.qq)
replayTextView.visibility = GONE
}
}
5、修改全屏按钮和非全屏按钮
override fun setScreenNormal() {
super.setScreenNormal()
//非全屏展示按钮
fullscreenButton.setImageResource(R.mipmap.qq)
}
override fun setScreenFullscreen() {
//全屏展示按钮
super.setScreenFullscreen()
}
6、如果要监听准确开始则需要startvideo方法
override fun startVideo() {
super.startVideo()
LogUtil.d("开始播放-这里可以做一些播放量统计之类的工作")
}
三、注意
1、修改UI时候尽量新建一个类继承JzvdStd方法,在其中重写对应的方法
2、修改内核的时候对应的类,需要从饺子源码中复制过去
|