From 3606815a410a32a6748a53dff8bce12333b8d34e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 10 Jan 2023 16:12:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=92=AD=E6=94=BE=E6=8A=9B?= =?UTF-8?q?=E9=94=99=E6=97=B6=E9=87=8D=E6=96=B0=E6=92=AD=E6=94=BE=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=BB=91=E5=8A=A8=E7=9B=B4=E6=92=AD=E9=97=B4?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=9B=B4=E6=92=AD=E9=97=B4=E7=94=BB=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/utils/LiveExoPlayerManager.java | 35 +++++++++++++++---- .../live/views/LivePlayRyViewHolder.java | 6 ++++ .../live/views/LiveRoomPlayViewHolder.java | 3 ++ .../live/views/PortraitLiveManager.java | 25 +++++++++++-- 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java index 3eb0dea13..dc2cd8c05 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -11,6 +11,7 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.analytics.AnalyticsListener; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; @@ -34,7 +35,7 @@ public class LiveExoPlayerManager { private int playBufferIndex = 0;//卡顿计数器 private final Handler handler; private static double log_buffer_time = 0, log_buffer_max_time; - private String url=""; + private String url = ""; public LiveExoPlayerManager(Context mContext) { DefaultLoadControl control = new DefaultLoadControl.Builder() @@ -123,7 +124,7 @@ public class LiveExoPlayerManager { public void onPlaybackStateChanged(int playbackState) { Player.Listener.super.onPlaybackStateChanged(playbackState); Log.i(TAG, "onPlaybackStateChanged 1: " + playbackState); - if (playbackState == Player.STATE_READY) { + if (playbackState == Player.STATE_READY && !player1.isPlaying()) { player2.stop(); player2.clearVideoSurface(); player1.play(); @@ -177,6 +178,15 @@ public class LiveExoPlayerManager { Player.Listener.super.onIsLoadingChanged(isLoading); Log.i(TAG, "onIsLoadingChanged: 1 " + isLoading); } + + @Override + public void onPlayerError(@NonNull PlaybackException error) { + Player.Listener.super.onPlayerError(error); + error.printStackTrace(); + String url=LiveExoPlayerManager.this.url; + LiveExoPlayerManager.this.url=null; + startUrl(url); + } }); player2.addListener(new Player.Listener() { @@ -184,7 +194,7 @@ public class LiveExoPlayerManager { public void onPlaybackStateChanged(int playbackState) { Player.Listener.super.onPlaybackStateChanged(playbackState); Log.i(TAG, "onPlaybackStateChanged 2: " + playbackState); - if (playbackState == Player.STATE_READY) { + if (playbackState == Player.STATE_READY && !player2.isPlaying()) { player1.stop(); player1.clearVideoSurface(); player2.play(); @@ -235,6 +245,14 @@ public class LiveExoPlayerManager { Player.Listener.super.onIsLoadingChanged(isLoading); Log.i(TAG, "onIsLoadingChanged: 2 " + isLoading); } + @Override + public void onPlayerError(@NonNull PlaybackException error) { + Player.Listener.super.onPlayerError(error); + error.printStackTrace(); + String url=LiveExoPlayerManager.this.url; + LiveExoPlayerManager.this.url=null; + startUrl(url); + } }); } @@ -244,7 +262,7 @@ public class LiveExoPlayerManager { * @param url 地址 */ public void startUrl(String url) { - if(url.equals(this.url))return; + if (url!=null&&url.equals(this.url)) return; Log.i(TAG, "startUrl: " + url + " > " + mainView.getResizeMode()); this.url = url; isSwitchUrl = true; @@ -265,8 +283,8 @@ public class LiveExoPlayerManager { * @param url 地址 */ public void switchUrl(String url) { - if(url.equals(this.url))return; - Log.i(TAG, "switchUrl: " + url +" src : "+this.url); + if (url!=null&&url.equals(this.url)) return; + Log.i(TAG, "switchUrl: " + url + " src : " + this.url); this.url = url; playBufferIndex = 0; isSwitchUrl = true; @@ -316,7 +334,10 @@ public class LiveExoPlayerManager { } public void clearFrame() { - //mainView.setKeepContentOnPlayerReset(false); + mainView.setKeepContentOnPlayerReset(false); + if (mainView.getVideoSurfaceView() != null) { + mainView.setPlayer(null); + } } /** diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 941b827f2..27c684339 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -370,6 +370,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } + @Override + public void clearFrame() { + super.clearFrame(); + mPlayer.clearFrame(); + } + @Override public void release() { mEnd = true; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index a663763dd..63bc39eea 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -97,6 +97,9 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public void switchStreamPk(boolean isPk) { } + public void clearFrame() { + } + public interface OnMicCallback { void onMikUpdate(); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index f35c9cf34..f9bf72956 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -244,12 +244,19 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mViewPager.setCanScroll(true); } }; + final Runnable loadRunnableGone = new Runnable() { + @Override + public void run() { + loading.setVisibility(View.GONE); + } + }; @Override public synchronized void onAdd(LiveBean data, int liveType, int liveTypeVal, int liveSdk) { isEnterRoom = false; openParametersModel = new OpenParametersModel(); mContext.runOnUiThread(new Runnable() { + @Override public void run() { Log.e("ImgLoader1", data.getAvatar()); @@ -264,9 +271,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe .setmLiveType(mLiveType) .setmLiveTypeVal(mLiveTypeVal))); loading.setVisibility(View.VISIBLE); + loading.setAlpha(0.6f); ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), ivBg); AnimationDrawable frameAnimation = (AnimationDrawable) ivLoading.getBackground(); frameAnimation.start(); + liveHandler.removeCallbacks(loadRunnableGone); if (mLivePlayViewHolder == null) { mLivePlayViewHolder = new LivePlayRyViewHolder(mContext, playContainer, 1); mLiveRoomViewHolder = new LiveRoomViewHolder(false, 1, mContext, mContainer, mSecondPage.findViewById(R.id.gift_gif), mSecondPage.findViewById(R.id.gift_svga), mContainerWrap, mContext.getWindowManager()); @@ -279,7 +288,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLivePlayViewHolder.setLoadViewListener(new LiveRoomPlayViewHolder.LoadingListener() { @Override public void onPlayer() { - liveHandler.postDelayed(()->loading.setVisibility(View.GONE),200); + liveHandler.postDelayed(loadRunnableGone, 350); } }); mLiveRoomViewHolder.subscribeActivityLifeCycle(); @@ -291,7 +300,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveLinkMicPresenter.setLiveSdk(mLiveSDK); mLiveLinkMicAnchorPresenter.setLiveSdk(mLiveSDK); } - if (mLiveRyLinkMicPkPresenter==null){ + if (mLiveRyLinkMicPkPresenter == null) { mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePlayViewHolder, false, null); } //去除主播离开画面 @@ -367,6 +376,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe landscape = data.getLiveInfo().getLandscape(); mLivePlayViewHolder.setLiveBeanLandscape(landscape); mLivePlayViewHolder.setLiveEnterRoomNewModel(data); + mLivePlayViewHolder.clearFrame(); int userClarityType = IMLoginManager.get(mContext).getInt(LiveRoomPlayViewHolder.PLAY_MODEL_KEY, -1); int anchorClarityType = data.getClarityType() - 1; if (userClarityType != anchorClarityType) { @@ -596,7 +606,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.showPrizePoolLevel(String.valueOf(giftPrizePoolLevel)); } } - liveHandler.postDelayed(() -> loading.setVisibility(View.GONE), 10_000); + liveHandler.postDelayed(loadRunnableGone, 10_000); } @@ -1794,6 +1804,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } + /** + * 幸运100%活动 + */ + public void lucky100(MsgModel model){ + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.lucky100(model); + } + } + public void messageBottom() { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.chatScrollToBottom();