diff --git a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayer.java b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayer.java index 1089bfd49..7d34d2dce 100644 --- a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayer.java +++ b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayer.java @@ -212,14 +212,14 @@ public interface CicadaPlayer { abstract public void setTraceId(String traceId); /** - * 设置音量。 + * 设置音量(非系统音量),范围0.0~2.0,当音量大于1.0时,可能出现噪音,不推荐使用。 * - * @param gain 范围[0,1] + * @param gain 范围[0,2] */ /**** - * Set the volume of the player. + * Set the volume of the player(Not system volume). The range is 0.0~2.0,it maybe lead to noise if set volume more then 1.0, not recommended. * - * @param gain Valid values: [0,1]. + * @param gain Valid values: [0,2]. */ abstract public void setVolume(float gain); @@ -674,10 +674,10 @@ public int getValue() { /** * 跳转到。不精准。 * - * @param position 位置 + * @param position 位置。单位毫秒。 */ /**** - * Specify a position for inaccurate seeking. + * Specify a position for inaccurate seeking. Unit: millisecond. * * @param position The specified position. */ @@ -686,13 +686,13 @@ public int getValue() { /** * 跳转到。 * - * @param position 位置。 + * @param position 位置。单位毫秒。 * @param seekMode seek模式。见{@link SeekMode}。 */ /**** * Seek to a specified position. * - * @param position The specified position. + * @param position The specified position. Unit: millisecond. * @param seekMode The specified seeking mode. See {@link SeekMode}. */ abstract public void seekTo(long position, SeekMode seekMode); @@ -1099,6 +1099,19 @@ public interface OnTrackChangedListener { * Subtitle display callback. */ public interface OnSubtitleDisplayListener { + + /** + * 外挂字幕添加成功 + * @param trackIndex 流id + * @param url 地址 + */ + /**** + * external subtitles added successfully + * @param trackIndex stream id + * @param url + */ + void onSubtitleExtAdded(int trackIndex,String url); + /** * 显示字幕 * @@ -1129,19 +1142,30 @@ public interface OnSubtitleDisplayListener { */ void onSubtitleHide(int trackIndex, long id); - /** - * 外挂字幕添加成功 - * @param trackIndex 流id - * @param url 地址 - */ - /**** - * external subtitles added successfully - * @param trackIndex stream id - * @param url - */ - void onSubtitleExtAdded(int trackIndex,String url); } + /** + * 添加外挂字幕 + * @param url 字幕地址 + */ + /**** + * Add external subtitles + * @param url subtitle address + */ + abstract public void addExtSubtitle(String url); + + /** + * 选择外挂字幕 + * @param trackIndex 字幕索引 + * @param select true:选择,false:关闭 + */ + /**** + * Select external subtitles + * @param trackIndex caption index + * @param select true: select, false: close + */ + abstract public void selectExtSubtitle(int trackIndex, boolean select); + /** * 设置字幕显示通知 * @@ -1268,26 +1292,50 @@ public static interface ConvertURLCallback { */ abstract public void reload(); + /** + * 设置多码率时默认播放的码率。将会选择与之最接近的一路流播放。 + * @param bandWidth 播放的码率。 + */ + /**** + * Set the default playback bitrate for multi-bit rate. The nearest stream will be selected. + * @param bandWidth bit rate . + */ + abstract public void setDefaultBandWidth(int bandWidth); /** - * 添加外挂字幕 - * @param url 字幕地址 + * */ - /**** - * add subtitle - * @param url Subtitle address - */ - void addExtSubtitle(String url); + public static class Option { + /** + * 渲染的fps。类型为Float + */ + /**** + * render fps. Return value type is Float + */ + public static Option RenderFPS = new Option("renderFps"); + + private String mValue; + + private Option(String value) { + mValue = value; + } + + public String getValue() { + return mValue; + } + } /** - * 选择外挂字幕 - * @param index 字幕索引 - * @param select true:选择,false:关闭 + * 获取播放器的参数 + * + * @param key 参数值 + * @return */ - /**** - * select subtitle - * @param index Subtitle index. - * @param select Set false to close. - */ - void selectExtSubtitle(int index, boolean select); + abstract public Object getOption(Option key); + + public interface OnVideoRenderedListener{ + void onVideoRendered(long timeMs , long pts); + } + + abstract public void setOnVideoRenderedListener(OnVideoRenderedListener l); } diff --git a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayerImpl.java b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayerImpl.java index a5977e248..9e2d9c7f0 100644 --- a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayerImpl.java +++ b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/CicadaPlayerImpl.java @@ -447,6 +447,30 @@ private void onStateChanged(int newState) { } } + private OnVideoRenderedListener mOutOnVideoRenderedListener = null; + private OnVideoRenderedListener mInnerOnVideoRenderedListener = new InnerVideoRenderedListener(this); + + private static class InnerVideoRenderedListener implements OnVideoRenderedListener { + private WeakReference cicadaPlayerImplWR; + + InnerVideoRenderedListener(CicadaPlayerImpl avpBase) { + cicadaPlayerImplWR = new WeakReference(avpBase); + } + + @Override + public void onVideoRendered(long timeMs, long pts) { + CicadaPlayerImpl cicadaPlayerImpl = cicadaPlayerImplWR.get(); + if (cicadaPlayerImpl != null) { + cicadaPlayerImpl.onVideoRendered(timeMs, pts); + } + } + } + + private void onVideoRendered(long timeMs, long pts){ + if(mOutOnVideoRenderedListener != null){ + mOutOnVideoRenderedListener.onVideoRendered(timeMs ,pts); + } + }; public CicadaPlayerImpl(Context context, String traceID) { mContext = context; @@ -726,6 +750,7 @@ public void selectTrack(int trackInfoIndex) { } @Override + @Deprecated public TrackInfo currentTrack(int type) { return mCorePlayer.getCurrentTrackInfo(type); } @@ -994,6 +1019,27 @@ public void addExtSubtitle(String url){ public void selectExtSubtitle(int index, boolean select){ mCorePlayer.selectExtSubtitle(index,select); } + + @Override + public void setDefaultBandWidth(int bandWidth) { + mCorePlayer.setDefaultBandWidth(bandWidth); + } + + @Override + public Object getOption(Option key) { + return mCorePlayer.getOption(key); + } + + @Override + public void setOnVideoRenderedListener(OnVideoRenderedListener listener){ + mOutOnVideoRenderedListener = listener; + if(mOutOnVideoRenderedListener!= null) { + mCorePlayer.setOnVideoRenderedListener(mInnerOnVideoRenderedListener); + }else{ + mCorePlayer.setOnVideoRenderedListener(null); + } + } + } diff --git a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/nativeclass/NativePlayerBase.java b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/nativeclass/NativePlayerBase.java index c4b1c4b68..7bac74e31 100644 --- a/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/nativeclass/NativePlayerBase.java +++ b/platform/Android/source/premierlibrary/src/main/java/com/cicada/player/nativeclass/NativePlayerBase.java @@ -385,6 +385,21 @@ public void setOption(String key, String value) { nSetOption(key, value); } + public Object getOption(CicadaPlayer.Option key) { + String optionValue = nGetOption(key.getValue()); + if (optionValue == null) { + return null; + } + if (key == CicadaPlayer.Option.RenderFPS) { + try { + return Float.valueOf(optionValue); + } catch (Exception e) { + return Float.valueOf("0"); + } + + } + return optionValue; + } public void setAutoPlay(boolean autoPlay) { log(TAG, "setAutoPlay = " + autoPlay); nSetAutoPlay(autoPlay); @@ -412,6 +427,10 @@ public void selectExtSubtitle(int index, boolean select){ nSelectExtSubtitle(index,select); } + public synchronized void setDefaultBandWidth(int bandWidth) { + nSetDefaultBandWidth(bandWidth); + } + public static String getSdkVersion() { return nGetSdkVersion(); } @@ -506,14 +525,20 @@ public static void setBlackType(int type) { protected native void nSetOption(String key, String value); + protected native String nGetOption(String key); + protected native void nSetAutoPlay(boolean autoPlay); + protected native void nEnableVideoRenderedCallback(boolean enable); + protected native boolean nIsAutoPlay(); protected native void nSnapShot(); protected native String nGetCacheFilePath(String URL); + protected native void nSetDefaultBandWidth(int bandWidth); + protected static native String nGetSdkVersion(); protected static native void nSetBlackType(int type); @@ -522,6 +547,7 @@ public static void setBlackType(int type) { //////==========--------------==================------------------================// private CicadaPlayer.OnVideoSizeChangedListener mOnVideoSizeChangedListener = null; + private CicadaPlayer.OnVideoRenderedListener mOnVideoRenderedListener = null; private CicadaPlayer.OnInfoListener mOnInfoListener = null; private CicadaPlayer.OnTrackReadyListener mOnTrackReadyListener = null; private CicadaPlayer.OnPreparedListener mOnPreparedListener = null; @@ -577,6 +603,12 @@ public void setOnVideoSizeChangedListener(CicadaPlayer.OnVideoSizeChangedListene mOnVideoSizeChangedListener = l; } + public void setOnVideoRenderedListener(CicadaPlayer.OnVideoRenderedListener l){ + log(TAG, "setOnVideoRenderedListener = " + l); + mOnVideoRenderedListener = l; + nEnableVideoRenderedCallback(l != null); + } + public void setOnTrackSelectRetListener(CicadaPlayer.OnTrackChangedListener l) { log(TAG, "setOnSwitchStreamResultListener = " + l); mOnTrackChangedListener = l; @@ -746,6 +778,18 @@ public void run() { }); } + protected void onVideoRendered(final long timeMs, final long pts) { + log(TAG, "onVideoRendered = " + timeMs + " , pts = " + pts); + mCurrentThreadHandler.post(new Runnable() { + @Override + public void run() { + if (mOnVideoRenderedListener != null) { + mOnVideoRenderedListener.onVideoRendered(timeMs, pts); + } + } + }); + } + protected void onStreamInfoGet(final MediaInfo mediaInfo) { log(TAG, "onStreamInfoGet = " + mediaInfo.getTrackInfos().size()); diff --git a/platform/Android/source/premierlibrary/src/main/jni/player/JavaPlayerConfig.cpp b/platform/Android/source/premierlibrary/src/main/jni/player/JavaPlayerConfig.cpp index c2d41ad89..5ef30a0f5 100644 --- a/platform/Android/source/premierlibrary/src/main/jni/player/JavaPlayerConfig.cpp +++ b/platform/Android/source/premierlibrary/src/main/jni/player/JavaPlayerConfig.cpp @@ -38,7 +38,7 @@ void JavaPlayerConfig::init(JNIEnv *env) if (gj_PlayerConfig_class == nullptr) { FindClass cls(env, playerConfigPath); gj_PlayerConfig_class = (jclass) env->NewGlobalRef( - cls.getClass()); + cls.getClass()); gj_PlayerConfig_Init = env->GetMethodID(gj_PlayerConfig_class, "", "()V"); @@ -103,7 +103,6 @@ jobject JavaPlayerConfig::getJPlayerConfig(JNIEnv *mEnv, const MediaPlayerConfig } jobject jPlayerConfig = mEnv->NewObject(gj_PlayerConfig_class, gj_PlayerConfig_Init); - mEnv->SetIntField(jPlayerConfig, gj_playerconfig_MaxProbeSize, playerConfig->maxProbeSize); mEnv->SetIntField(jPlayerConfig, gj_playerconfig_MaxBufferedPacketDuration, playerConfig->maxBufferDuration); mEnv->SetIntField(jPlayerConfig, gj_playerconfig_FirstStartBufferLevel, @@ -193,7 +192,6 @@ MediaPlayerConfig JavaPlayerConfig::convertTo(JNIEnv *env, jobject playerConfig) config.highBufferDuration = highBufferLevel; config.maxBufferDuration = maxBufferedPacketDuration; config.maxDelayTime = maxDelayTime; - config.maxProbeSize = maxProbeSize; config.networkTimeout = networkTimeout; config.bClearShowWhenStop = clearFrameWhenStop; config.bEnableTunnelRender = enableTunnelRender; diff --git a/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.cpp b/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.cpp index 7004b782a..1c5561caf 100644 --- a/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.cpp +++ b/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.cpp @@ -182,7 +182,6 @@ void NativeBase::java_SelectTrack(JNIEnv *env, jobject instance, jint index) player->SelectTrack(index); } - void NativeBase::java_Prepare(JNIEnv *env, jobject instance) { AF_TRACE; @@ -791,6 +790,17 @@ jstring NativeBase::java_GetCacheFilePathByURL(JNIEnv *env, jobject instance, js return nullptr; } + +void NativeBase::java_SetDefaultBandWidth(JNIEnv *env, jobject instance, jint defaultBandWidth) +{ + AF_TRACE; + MediaPlayer *player = getPlayer(env, instance); + + if (player != nullptr) { + player->SetDefaultBandWidth((int)defaultBandWidth); + } +} + //callback... void NativeBase::init(JNIEnv *env) @@ -933,6 +943,7 @@ static JNINativeMethod nativePlayer_method_table[] = { {"nGetSdkVersion", "()Ljava/lang/String;", (void *) NativeBase::java_GetSdkVersion}, {"nSetBlackType", "(I)V", (void *) NativeBase::java_SetBlackType}, {"nGetCacheFilePath", "(Ljava/lang/String;)Ljava/lang/String;", (void *) NativeBase::java_GetCacheFilePathByURL}, + {"nSetDefaultBandWidth", "(I)V", (void *) NativeBase::java_SetDefaultBandWidth}, }; diff --git a/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.h b/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.h index 5e3d37a8c..0da8f381f 100644 --- a/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.h +++ b/platform/Android/source/premierlibrary/src/main/jni/player/NativeBase.h @@ -137,6 +137,7 @@ class NativeBase { static jstring java_GetCacheFilePathByURL(JNIEnv *env, jobject instance, jstring URL); + static void java_SetDefaultBandWidth(JNIEnv *env , jobject instance , jint defaultBandWidth); public: static void jni_onError(int64_t code, const void *msg, /*void *extra, */void *userData);