From 0c9d2132fb2e318a200795d6a6a9b9b4a4539410 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 29 Jun 2020 15:01:10 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=AD=90=E7=B1=BB?= =?UTF-8?q?=E7=BB=A7=E6=89=BFJzvdStd=E6=97=B6=20=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=88=B6=E7=B1=BBviewid,=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E6=89=BE=E4=B8=8D=E5=88=B0=20viewId=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/src/main/res/values/ids.xml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 library/src/main/res/values/ids.xml diff --git a/library/src/main/res/values/ids.xml b/library/src/main/res/values/ids.xml new file mode 100644 index 00000000..3d0d301d --- /dev/null +++ b/library/src/main/res/values/ids.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From e2c83633381016d8c6a0e3c0aaa71fefef2bf618 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 29 Jun 2020 16:31:58 +0800 Subject: [PATCH 02/17] =?UTF-8?q?exoplayer=E4=BE=9D=E8=B5=96=E4=BB=8E2.10.?= =?UTF-8?q?4=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E5=88=B02.11.3=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20=20=E5=B9=B6=E6=8A=8A@Deprecated=20api=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=9B=BF=E6=8D=A2=E6=88=90=E6=9C=80=E6=96=B0=E7=9A=84?= =?UTF-8?q?api=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/build.gradle | 2 +- .../cn/jzvd/demo/CustomMedia/JZMediaExo.java | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index a0100a43..fee89475 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -56,7 +56,7 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'com.danikula:videocache:2.7.0' implementation 'com.github.bumptech.glide:glide:4.11.0' - implementation 'com.google.android.exoplayer:exoplayer:2.10.4' + implementation 'com.google.android.exoplayer:exoplayer:2.11.3' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-core:1.0.15' diff --git a/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaExo.java b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaExo.java index 3ec1d697..7d9636ca 100644 --- a/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaExo.java +++ b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaExo.java @@ -12,15 +12,14 @@ import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.LoadControl; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.Timeline; -import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; +import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; @@ -70,21 +69,29 @@ public void prepare() { mMediaHandler = new Handler(context.getMainLooper());//主线程还是非主线程,就在这里 handler = new Handler(); mMediaHandler.post(() -> { - BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); + TrackSelection.Factory videoTrackSelectionFactory = - new AdaptiveTrackSelection.Factory(bandwidthMeter); + new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = - new DefaultTrackSelector(videoTrackSelectionFactory); + new DefaultTrackSelector(context,videoTrackSelectionFactory); + + LoadControl loadControl = new DefaultLoadControl.Builder() + .setAllocator(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE)) + .setBufferDurationsMs( 360000, 600000, 1000, 5000) + .setPrioritizeTimeOverSizeThresholds(false) + .setTargetBufferBytes(C.LENGTH_UNSET) + .createDefaultLoadControl(); - LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE), - 360000, 600000, 1000, 5000, - C.LENGTH_UNSET, - false); + BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build(); // 2. Create the player RenderersFactory renderersFactory = new DefaultRenderersFactory(context); - simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl); + simpleExoPlayer = new SimpleExoPlayer.Builder(context, renderersFactory) + .setTrackSelector(trackSelector) + .setLoadControl(loadControl) + .setBandwidthMeter(bandwidthMeter) + .build() ; // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, context.getResources().getString(R.string.app_name))); @@ -93,9 +100,13 @@ public void prepare() { MediaSource videoSource; if (currUrl.contains(".m3u8")) { videoSource = new HlsMediaSource.Factory(dataSourceFactory) - .createMediaSource(Uri.parse(currUrl), handler, null); + .createMediaSource(Uri.parse(currUrl)); + //addEventListener 这里只有两个参数都要传入值才可以成功设置 + // 否者会被断言 Assertions.checkArgument(handler != null && eventListener != null); + // 并且报错 IllegalArgumentException() 所以不需要添加监听器时 注释掉 + // videoSource .addEventListener( handler, null); } else { - videoSource = new ExtractorMediaSource.Factory(dataSourceFactory) + videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(currUrl)); } simpleExoPlayer.addVideoListener(this); From 224b0d473f9a167300e06faebb0fc53d34752160 Mon Sep 17 00:00:00 2001 From: Nathen <1066666651@qq.com> Date: Wed, 1 Jul 2020 01:32:34 +0800 Subject: [PATCH 03/17] kotlin for new code --- build.gradle | 2 ++ library/build.gradle | 6 ++++++ library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt diff --git a/build.gradle b/build.gradle index a1e614b6..4ac733c3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.72' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/library/build.gradle b/library/build.gradle index 06ae721e..ba4b1fcc 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 29 @@ -23,6 +24,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } apply from: '../gradle/build_upload.gradle' +repositories { + mavenCentral() +} diff --git a/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt b/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt new file mode 100644 index 00000000..60a7919f --- /dev/null +++ b/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt @@ -0,0 +1,2 @@ +package org.jzvd.jzvideo + From 64e23d7ba7a51ca0c2a109f6a1dc8310c70c4b66 Mon Sep 17 00:00:00 2001 From: Nathen <1066666651@qq.com> Date: Tue, 7 Jul 2020 01:46:37 +0800 Subject: [PATCH 04/17] JZVideoA class --- .../main/java/org/jzvd/jzvideo/JZVideoA.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt b/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt index 60a7919f..bdb5e4b6 100644 --- a/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt +++ b/library/src/main/java/org/jzvd/jzvideo/JZVideoA.kt @@ -1,2 +1,37 @@ package org.jzvd.jzvideo +import android.content.Context +import android.util.AttributeSet +import android.widget.RelativeLayout + +const val TAG = "JZVD" + + +open class JZVideoA : RelativeLayout { + + enum class State { + IDLE, NORMAL, PREPARING, PREPARING_CHANGE_URL, PREPARING_PLAYING, + PREPARED, PLAYING, PAUSE, COMPLETE, ERROR + } + + enum class Screen { + NORMAL, FULLSCREEN, TINY + } + + lateinit var state: State + + + constructor(ctx: Context) : super(ctx) { + } + + constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs) { + } + + companion object { + @JvmStatic + fun releaseAllVideos() { + + } + } + +} \ No newline at end of file From c9d755949210c10adcbb529cd258c98a2c4fc19f Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 27 Aug 2020 13:25:13 +0200 Subject: [PATCH 05/17] Fixed player name in sample layout --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 768e49b2..feaa3306 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ implementation 'cn.jzvd:jiaozivideoplayer:7.4.2' 2.添加布局 ```xml - From f3c4f2dfd70c0f4c8a9b2b5596cba9a2e91be788 Mon Sep 17 00:00:00 2001 From: Nathen <1066666651@qq.com> Date: Mon, 31 Aug 2020 22:06:32 +0800 Subject: [PATCH 06/17] upgrade env --- build.gradle | 2 +- demo/build.gradle | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 4ac733c3..54120b91 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/demo/build.gradle b/demo/build.gradle index ef6513bb..df2f3e66 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 29 - buildToolsVersion = '29.0.3' + compileSdkVersion 30 + buildToolsVersion "30.0.2" defaultConfig { applicationId "cn.jzvd.demo" minSdkVersion 16 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 104 versionName "7.4.2" ndk { From a7c4b9d1c9ef44af4f5b5c24dcc8a36e475762bd Mon Sep 17 00:00:00 2001 From: kHRYSTAL <723526676@qq.com> Date: Tue, 1 Sep 2020 17:56:44 +0800 Subject: [PATCH 07/17] =?UTF-8?q?add[JZMediaAliyun]:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E6=92=AD=E6=94=BE=E5=86=85=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 + demo/build.gradle | 2 + .../java/cn/jzvd/demo/ApplicationDemo.java | 3 + .../jzvd/demo/CustomMedia/JZMediaAliyun.java | 277 ++++++++++++++++++ .../demo/Tab_1_Basic/CustomMediaActivity.java | 9 + .../activity_api_custom_mediaplayer.xml | 9 + demo/src/main/res/values-zh/strings.xml | 1 + demo/src/main/res/values/strings.xml | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- 9 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java diff --git a/build.gradle b/build.gradle index 54120b91..353dce49 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { repositories { jcenter() google() + maven { url 'https://maven.aliyun.com/repository/releases' } } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' @@ -21,6 +22,7 @@ allprojects { google() maven { url "https://jitpack.io" } maven { url "https://maven.google.com" } + maven { url 'https://maven.aliyun.com/repository/releases' } } } diff --git a/demo/build.gradle b/demo/build.gradle index df2f3e66..cfa92f47 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -62,4 +62,6 @@ dependencies { implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-core:1.0.15' implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-native:1.0.15' implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4' + implementation 'com.aliyun.sdk.android:AliyunPlayer:4.5.0-full' + implementation 'com.alivc.conan:AlivcConan:0.9.5' } diff --git a/demo/src/main/java/cn/jzvd/demo/ApplicationDemo.java b/demo/src/main/java/cn/jzvd/demo/ApplicationDemo.java index 4b2eab70..8c38b32d 100644 --- a/demo/src/main/java/cn/jzvd/demo/ApplicationDemo.java +++ b/demo/src/main/java/cn/jzvd/demo/ApplicationDemo.java @@ -12,6 +12,8 @@ */ public class ApplicationDemo extends Application { + public static Context APP_CONTEXT = null; + private HttpProxyCacheServer proxy; public static HttpProxyCacheServer getProxy(Context context) { @@ -22,6 +24,7 @@ public static HttpProxyCacheServer getProxy(Context context) { @Override public void onCreate() { super.onCreate(); + APP_CONTEXT = this; // LeakCanary.install(this); } diff --git a/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java new file mode 100644 index 00000000..d51d3ee9 --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java @@ -0,0 +1,277 @@ +package cn.jzvd.demo.CustomMedia; + +import android.graphics.SurfaceTexture; +import android.os.Handler; +import android.util.Log; +import android.view.Surface; + +import com.aliyun.player.AliPlayer; +import com.aliyun.player.AliPlayerFactory; +import com.aliyun.player.IPlayer; +import com.aliyun.player.bean.ErrorInfo; +import com.aliyun.player.bean.InfoBean; +import com.aliyun.player.bean.InfoCode; +import com.aliyun.player.nativeclass.PlayerConfig; +import com.aliyun.player.source.UrlSource; + +import cn.jzvd.JZMediaInterface; +import cn.jzvd.Jzvd; +import cn.jzvd.demo.ApplicationDemo; + +/** + * usage: 阿里云播放器内核 + * author: kHRYSTAL + * create time: 2020-09-01 + * update time: + * email: 723526676@qq.com + */ +public class JZMediaAliyun extends JZMediaInterface implements IPlayer.OnPreparedListener, IPlayer.OnVideoSizeChangedListener, IPlayer.OnCompletionListener, IPlayer.OnErrorListener, IPlayer.OnInfoListener, IPlayer.OnSeekCompleteListener, IPlayer.OnRenderingStartListener, IPlayer.OnLoadingStatusListener { + + private static final String TAG = JZMediaAliyun.class.getSimpleName(); + private static final int FROM_ALIYUN_PLAYER_INFO = 0x1688; + + AliPlayer aliyunMediaPlayer; + private boolean isPlaying; + private long mCurrentPosition; + + public JZMediaAliyun(Jzvd jzvd) { + super(jzvd); + } + + @Override + public void start() { + if (aliyunMediaPlayer != null) { + isPlaying = true; + aliyunMediaPlayer.start(); + handler.post(() -> jzvd.onStatePlaying()); // 需要手动调用开始播放 改变ui播放状态 + } + } + + @Override + public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { + if (SAVED_SURFACE == null) { + SAVED_SURFACE = surface; + prepare(); + } else { + jzvd.textureView.setSurfaceTexture(SAVED_SURFACE); + } + } + + @Override + public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { + } + + @Override + public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { + return false; + } + + @Override + public void onSurfaceTextureUpdated(SurfaceTexture surface) { + + } + + @Override + public void prepare() { + release(); + mMediaHandler = new Handler(); + handler = new Handler(); + mMediaHandler.post(() -> { + aliyunMediaPlayer = AliPlayerFactory.createAliPlayer(ApplicationDemo.APP_CONTEXT); + + //region 阿里云播放器基本设置 具体参考: {@link https://help.aliyun.com/document_detail/124714.html?spm=a2c4g.11186623.6.1083.2dbf2722XQM0Mr} + //先获取配置 + PlayerConfig config = aliyunMediaPlayer.getConfig(); + //设置网络超时时间,单位ms + config.mNetworkTimeout = 5000; + //设置超时重试次数。每次重试间隔为networkTimeout。networkRetryCount=0则表示不重试,重试策略app决定,默认值为2 + config.mNetworkRetryCount = 2; + // 配置请求头 refer UA + //定义header +// String[] headers = new String[1]; +// headers[0]="Host:xxx.com";//比如需要设置Host到header中。 +// config.setCustomHeaders(headers); +// config.mUserAgent = "需要设置的UserAgent"; + //最大延迟。注意:直播有效。当延时比较大时,播放器sdk内部会追帧等,保证播放器的延时在这个范围内。 + config.mMaxDelayTime = 5000; + // 最大缓冲区时长。单位ms。播放器每次最多加载这么长时间的缓冲数据。 + config.mMaxBufferDuration = 50000; + //高缓冲时长。单位ms。当网络不好导致加载数据时,如果加载的缓冲时长到达这个值,结束加载状态。 + config.mHighBufferDuration = 3000; + // 起播缓冲区时长。单位ms。这个时间设置越短,起播越快。也可能会导致播放之后很快就会进入加载状态。 + config.mStartBufferDuration = 500; + //设置配置给播放器 + aliyunMediaPlayer.setConfig(config); + //endregion + +// aliyunMediaPlayer.setAutoPlay(true); // 是否自动播放 +// aliyunMediaPlayer.setLoop(true); // 是否循环播放 + + //region 监听 + aliyunMediaPlayer.setOnPreparedListener(JZMediaAliyun.this); // 准备成功事件 + aliyunMediaPlayer.setOnVideoSizeChangedListener(JZMediaAliyun.this); // 视频分辨率变化回调 + aliyunMediaPlayer.setOnCompletionListener(JZMediaAliyun.this); // 播放完成事件 + aliyunMediaPlayer.setOnErrorListener(JZMediaAliyun.this); // 出错事件 + aliyunMediaPlayer.setOnInfoListener(JZMediaAliyun.this); //其他信息的事件,type包括了:循环播放开始,缓冲位置,当前播放位置,自动播放开始等 + aliyunMediaPlayer.setOnSeekCompleteListener(JZMediaAliyun.this); // 拖动事件 + aliyunMediaPlayer.setOnRenderingStartListener(JZMediaAliyun.this); // 首帧渲染显示事件 + aliyunMediaPlayer.setOnLoadingStatusListener(JZMediaAliyun.this); + //endregion + + //设置配置给播放器 + try { + // 创建DataSource,准备播放 可通过jzDataSource区分是否加密 + UrlSource urlSource = new UrlSource(); + urlSource.setUri(jzvd.jzDataSource.getCurrentUrl().toString()); +// 加密播放配置 以下的key可以通过jzDataSource去获取 +// VidSts vidSts = new VidSts(); +// vidSts.setVid("videoId"); +// vidSts.setAccessKeyId("akId"); +// vidSts.setAccessKeySecret("akSecret"); +// vidSts.setSecurityToken("authToken"); +// vidSts.setRegion("cn-shanghai"); + aliyunMediaPlayer.setDataSource(urlSource); + aliyunMediaPlayer.setSurface(new Surface(SAVED_SURFACE)); + aliyunMediaPlayer.prepare(); + } catch (Exception e) { + Log.e(TAG, e.getMessage()); + } + }); + } + + @Override + public void pause() { + if (aliyunMediaPlayer != null) { + isPlaying = false; + aliyunMediaPlayer.pause(); + } + } + + @Override + public boolean isPlaying() { + return isPlaying; + } + + @Override + public void seekTo(long time) { + if (aliyunMediaPlayer != null) + aliyunMediaPlayer.seekTo(time); + } + + @Override + public void release() { + if (mMediaHandler != null && aliyunMediaPlayer != null) { + AliPlayer tmpMediaPlayer = aliyunMediaPlayer; + JZMediaInterface.SAVED_SURFACE = null; + isPlaying = false; + mCurrentPosition = 0L; + mMediaHandler.post(() -> { + tmpMediaPlayer.setSurface(null); + tmpMediaPlayer.release(); + }); + aliyunMediaPlayer = null; + } + } + + @Override + public long getCurrentPosition() { + if (aliyunMediaPlayer != null) { + return mCurrentPosition; + } + return 0L; + } + + @Override + public long getDuration() { + if (aliyunMediaPlayer != null) { + return aliyunMediaPlayer.getDuration(); + } + return 0L; + } + + @Override + public void setVolume(float leftVolume, float rightVolume) { + aliyunMediaPlayer.setVolume(Math.max(leftVolume, rightVolume)); + } + + @Override + public void setSpeed(float speed) { + if (aliyunMediaPlayer != null) + aliyunMediaPlayer.setSpeed(speed); + } + + @Override + public void setSurface(Surface surface) { + if (aliyunMediaPlayer != null) + aliyunMediaPlayer.setSurface(surface); + } + + @Override + public void onPrepared() { + handler.post(() -> jzvd.onPrepared()); + } + + @Override + public void onVideoSizeChanged(int i, int i1) { + handler.post(() -> jzvd.onVideoSizeChanged(aliyunMediaPlayer.getVideoWidth(), aliyunMediaPlayer.getVideoHeight())); + } + + @Override + public void onCompletion() { + isPlaying = false; + mCurrentPosition = 0L; + handler.post(() -> jzvd.onCompletion()); + } + + @Override + public void onError(ErrorInfo errorInfo) { + isPlaying = false; + mCurrentPosition = 0L; + // 具体参考阿里云播放器错误码 + handler.post(() -> jzvd.onError(errorInfo.getCode().getValue(), errorInfo.getCode().getValue())); + } + + @Override + public void onInfo(InfoBean infoBean) { + if (infoBean.getCode() == InfoCode.AutoPlayStart) { + //自动播放开始,需要设置播放状态 + isPlaying = true; + } else if (infoBean.getCode() == InfoCode.BufferedPosition) { + //更新bufferedPosition + long videoBufferedPosition = infoBean.getExtraValue(); + handler.post(() -> jzvd.setBufferProgress((int) videoBufferedPosition)); + } else if (infoBean.getCode() == InfoCode.CurrentPosition) { + //更新currentPosition + mCurrentPosition = infoBean.getExtraValue(); + } else { + handler.post(() -> jzvd.onInfo(FROM_ALIYUN_PLAYER_INFO, infoBean.getCode().getValue())); + } + } + + @Override + public void onSeekComplete() { + //拖动结束 + handler.post(() -> jzvd.onSeekComplete()); + } + + @Override + public void onRenderingStart() { + // 首帧渲染回调 + } + + @Override + public void onLoadingBegin() { + //缓冲开始 + } + + @Override + public void onLoadingProgress(int percent, float kbps) { + // 正在缓冲进度 可配置ui 参数1显示secondary进度条 参数2控制显示kbp/s + handler.post(() -> jzvd.setBufferProgress(percent)); + } + + @Override + public void onLoadingEnd() { + //缓冲结束 + } +} diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java index e2bf3807..4fe9ddc4 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java @@ -13,6 +13,7 @@ import cn.jzvd.JZMediaSystem; import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; +import cn.jzvd.demo.CustomMedia.JZMediaAliyun; import cn.jzvd.demo.CustomMedia.JZMediaExo; import cn.jzvd.demo.CustomMedia.JZMediaIjk; import cn.jzvd.demo.R; @@ -70,6 +71,14 @@ public void clickChangeToExo(View view) { Toast.makeText(this, "Change to ExoPlayer", Toast.LENGTH_SHORT).show(); } + public void clickChangeToAliyun(View view) { + Jzvd.releaseAllVideos(); + jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" + , "饺子梭哈", JzvdStd.SCREEN_NORMAL, JZMediaAliyun.class); + jzvdStd.startVideo(); + Toast.makeText(this, "Change to AliyunPlayer", Toast.LENGTH_SHORT).show(); + } + @Override public void onBackPressed() { diff --git a/demo/src/main/res/layout/activity_api_custom_mediaplayer.xml b/demo/src/main/res/layout/activity_api_custom_mediaplayer.xml index c78ecad2..2cf8aefc 100644 --- a/demo/src/main/res/layout/activity_api_custom_mediaplayer.xml +++ b/demo/src/main/res/layout/activity_api_custom_mediaplayer.xml @@ -36,4 +36,13 @@ android:layout_marginBottom="8dp" android:onClick="clickChangeToExo" android:text="@string/change_exo" /> + +