From 25d5884e3dd5bf3ee1a777b44a4f4051c6058e3f Mon Sep 17 00:00:00 2001 From: yangyakun Date: Wed, 25 Dec 2024 17:03:05 +0800 Subject: [PATCH] =?UTF-8?q?[6.8.4]=20[fix]=20[=E9=81=93=E8=B7=AF=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=92=8C=E5=B9=BF=E5=91=8A=E8=A7=86=E9=A2=91=E5=86=B2?= =?UTF-8?q?=E7=AA=81]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/module/utils/CustomManager.java | 188 ++++++++++++++++++ .../wigets/media/MediaPlayerCustomView.kt | 47 +++++ OCH/common/common/src/main/res/values/ids.xml | 5 + 3 files changed, 240 insertions(+) create mode 100644 OCH/common/common/src/main/java/com/mogo/och/common/module/utils/CustomManager.java create mode 100644 OCH/common/common/src/main/res/values/ids.xml diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/CustomManager.java b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/CustomManager.java new file mode 100644 index 0000000000..d41245c3af --- /dev/null +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/CustomManager.java @@ -0,0 +1,188 @@ +package com.mogo.och.common.module.utils; + +import android.app.Activity; +import android.content.Context; +import android.text.TextUtils; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; + +import com.shuyu.gsyvideoplayer.GSYVideoBaseManager; +import com.shuyu.gsyvideoplayer.player.IPlayerManager; +import com.shuyu.gsyvideoplayer.player.IjkPlayerManager; +import com.shuyu.gsyvideoplayer.utils.CommonUtil; +import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer; +import com.mogo.och.common.module.R; + +import java.util.HashMap; +import java.util.Map; + +import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideNavKey; + +/** + * 多个播放的管理器 + * Created by guoshuyu on 2018/1/31. + */ + +public class CustomManager extends GSYVideoBaseManager { + + public static final int SMALL_ID = R.id.custom_small_id; + + public static final int FULLSCREEN_ID = R.id.custom_full_id; + + public static String TAG = "GSYVideoManager"; + + private static Map sMap = new HashMap<>(); + + + public CustomManager() { + init(); + } + + @Override + protected IPlayerManager getPlayManager() { + return new IjkPlayerManager(); + } + + /** + * 退出全屏,主要用于返回键 + * + * @return 返回是否全屏 + */ + @SuppressWarnings("ResourceType") + public static boolean backFromWindowFull(Context context, String key) { + boolean backFrom = false; + ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(context)).findViewById(Window.ID_ANDROID_CONTENT); + View oldF = vp.findViewById(FULLSCREEN_ID); + if (oldF != null) { + backFrom = true; + hideNavKey(context); + if (getCustomManager(key).lastListener() != null) { + getCustomManager(key).lastListener().onBackFullscreen(); + } + } + return backFrom; + } + + /** + * 页面销毁了记得调用是否所有的video + */ + public static void releaseAllVideos(String key) { + if (getCustomManager(key).listener() != null) { + getCustomManager(key).listener().onCompletion(); + } + getCustomManager(key).releaseMediaPlayer(); + } + + + /** + * 暂停播放 + */ + public void onPause(String key) { + if (getCustomManager(key).listener() != null) { + getCustomManager(key).listener().onVideoPause(); + } + } + + /** + * 恢复播放 + */ + public void onResume(String key) { + if (getCustomManager(key).listener() != null) { + getCustomManager(key).listener().onVideoResume(); + } + } + + + /** + * 恢复暂停状态 + * + * @param seek 是否产生seek动作,直播设置为false + */ + public void onResume(String key, boolean seek) { + if (getCustomManager(key).listener() != null) { + getCustomManager(key).listener().onVideoResume(seek); + } + } + + + /** + * 单例管理器 + */ + public static synchronized Map instance() { + return sMap; + } + + /** + * 单例管理器 + */ + public static synchronized CustomManager getCustomManager(String key) { + if (TextUtils.isEmpty(key)) { + throw new IllegalStateException("key not be empty"); + } + CustomManager customManager = sMap.get(key); + if (customManager == null) { + customManager = new CustomManager(); + sMap.put(key, customManager); + } + return customManager; + } + + public static void onPauseAll() { + if (sMap.size() > 0) { + for (Map.Entry header : sMap.entrySet()) { + header.getValue().onPause(header.getKey()); + } + } + } + + public static void onResumeAll() { + if (sMap.size() > 0) { + for (Map.Entry header : sMap.entrySet()) { + header.getValue().onResume(header.getKey()); + } + } + } + + /** + * 恢复暂停状态 + * + * @param seek 是否产生seek动作 + */ + public static void onResumeAll(boolean seek) { + if (sMap.size() > 0) { + for (Map.Entry header : sMap.entrySet()) { + header.getValue().onResume(header.getKey(), seek); + } + } + } + + public static void clearAllVideo() { + if (sMap.size() > 0) { + for (Map.Entry header : sMap.entrySet()) { + CustomManager.releaseAllVideos(header.getKey()); + } + } + sMap.clear(); + } + + public static void removeManager(String key) { + sMap.remove(key); + } + + /** + * 当前是否全屏状态 + * + * @return 当前是否全屏状态, true代表是。 + */ + @SuppressWarnings("ResourceType") + public static boolean isFullState(Activity activity) { + ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(activity)).findViewById(Window.ID_ANDROID_CONTENT); + final View full = vp.findViewById(FULLSCREEN_ID); + GSYVideoPlayer gsyVideoPlayer = null; + if (full != null) { + gsyVideoPlayer = (GSYVideoPlayer) full; + } + return gsyVideoPlayer != null; + } +} diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/media/MediaPlayerCustomView.kt b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/media/MediaPlayerCustomView.kt index 83ad2d60ec..887d26c5ea 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/media/MediaPlayerCustomView.kt +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/wigets/media/MediaPlayerCustomView.kt @@ -1,6 +1,7 @@ import android.content.Context import android.media.AudioManager import android.net.Uri +import android.text.TextUtils import android.util.AttributeSet import android.widget.ImageView import android.widget.RelativeLayout @@ -13,6 +14,7 @@ import com.mogo.eagle.core.utilcode.util.FileUtils import com.mogo.eagle.core.utilcode.util.ThreadUtils import com.mogo.eagle.core.utilcode.util.UiThreadHandler import com.mogo.eagle.core.widget.media.video.TextureVideoViewOutlineProvider +import com.mogo.och.common.module.utils.CustomManager import com.mogo.och.common.module.R import com.mogo.och.common.module.wigets.media.MediaFileCacheManager import com.mogo.och.common.module.wigets.media.MediaItem @@ -22,8 +24,10 @@ import com.mogo.skin.utils.SkinResources import com.mogo.skin.widget.SkinImageView import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack +import com.shuyu.gsyvideoplayer.utils.Debuger import com.shuyu.gsyvideoplayer.utils.GSYVideoType import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer +import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge import me.jessyan.autosize.utils.AutoSizeUtils import java.io.File @@ -250,6 +254,49 @@ class AdvanceGSYVideoPlayer : StandardGSYVideoPlayer { GSYVideoType.setRenderType(GSYVideoType.GLSURFACE) } + override fun init(context: Context) { + super.init(context) + onAudioFocusChangeListener = + AudioManager.OnAudioFocusChangeListener { focusChange -> + when (focusChange) { + AudioManager.AUDIOFOCUS_GAIN -> {} + AudioManager.AUDIOFOCUS_LOSS -> { + //todo 判断如果不是外界造成的就不处理 + } + + AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { + //todo 判断如果不是外界造成的就不处理 + } + + AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {} + } + } + } + + override fun getGSYVideoManager(): GSYVideoViewBridge { + CustomManager.getCustomManager(getKey()).initContext(getContext().getApplicationContext()); + return CustomManager.getCustomManager(getKey()); + } + + override fun releaseVideos() { + CustomManager.releaseAllVideos(getKey()) + } + + override fun backFromFull(context: Context?): Boolean { + return CustomManager.backFromWindowFull(context, getKey()) + } + + fun getKey(): String { + if (mPlayPosition == -22) { + Debuger.printfError(javaClass.simpleName + " used getKey() " + "******* PlayPosition never set. ********") + } + if (TextUtils.isEmpty(mPlayTag)) { + Debuger.printfError(javaClass.simpleName + " used getKey() " + "******* PlayTag never set. ********") + } + Logger.d("MediaLoopPlayView", "key ${(MediaLoopPlayView.TAG + mPlayPosition).toString() + mPlayTag}") + return (MediaLoopPlayView.TAG + mPlayPosition).toString() + mPlayTag + } + override fun hideAllWidget() { Logger.d(MediaLoopPlayView.TAG, "AdvanceGSYVideoPlayer,hideAllWidget") } diff --git a/OCH/common/common/src/main/res/values/ids.xml b/OCH/common/common/src/main/res/values/ids.xml new file mode 100644 index 0000000000..3b52790d4e --- /dev/null +++ b/OCH/common/common/src/main/res/values/ids.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file