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 c23774c61..59292afa7 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -157,7 +157,7 @@ public class LiveExoPlayerManager { mainView.setPlayer(player1); status = MODEL_PLAY1; isSwitchUrl = false; - if(getNextPlayer().isPlaying()){ + if (getNextPlayer().isPlaying()) { getNextPlayer().stop(); } if (listener != null) { @@ -186,9 +186,7 @@ public class LiveExoPlayerManager { public void onPlayerError(@NonNull PlaybackException error) { Player.Listener.super.onPlayerError(error); error.printStackTrace(); - String url=LiveExoPlayerManager.this.url; - LiveExoPlayerManager.this.url=null; - startUrl(url); + replay(); } }); @@ -227,7 +225,7 @@ public class LiveExoPlayerManager { //ToastUtil.show(String.format(Locale.CHINA, "从加载到播放 = %.3f,最大耗时 = %.3f", tmp, log_buffer_max_time)); log_buffer_time = -1; status = MODEL_PLAY2; - if(getNextPlayer().isPlaying()){ + if (getNextPlayer().isPlaying()) { getNextPlayer().stop(); } isSwitchUrl = false; @@ -251,13 +249,12 @@ 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); + replay(); } }); } @@ -268,7 +265,7 @@ public class LiveExoPlayerManager { * @param url 地址 */ public void startUrl(String url) { - if (url!=null&&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; @@ -289,7 +286,7 @@ public class LiveExoPlayerManager { * @param url 地址 */ public void switchUrl(String url) { - if (url!=null&&url.equals(this.url)) return; + if (url != null && url.equals(this.url)) return; Log.i(TAG, "switchUrl: " + url + " src : " + this.url); this.url = url; playBufferIndex = 0; @@ -338,9 +335,10 @@ public class LiveExoPlayerManager { public void play() { getNowPlayer().play(); } - public void replay(){ - String tmp=url; - url=null; + + public void replay() { + String tmp = url; + url = null; startUrl(tmp); } 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 7459fd7e0..eb5c6102c 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -80,7 +80,9 @@ import cn.rongcloud.rtc.base.RCRTCMediaType; import cn.rongcloud.rtc.base.RCRTCParamsType; import cn.rongcloud.rtc.base.RCRTCRemoteVideoFrame; import cn.rongcloud.rtc.base.RCRTCRoomType; +import cn.rongcloud.rtc.base.RCRTCStreamType; import cn.rongcloud.rtc.base.RTCErrorCode; +import cn.rongcloud.rtc.center.stream.RCRTCAudioInputStreamImpl; public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @@ -342,7 +344,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void switchStreamPk(boolean isPk) { super.switchStreamPk(isPk); Log.i(TAG, "switchStreamPk: isPk1" + isPk + " tmp = " + !tmpPk + " isPk2 = " + this.isPk); - if(this.isPk&&tmpPk)return; + if (this.isPk && tmpPk) return; if (isPk && !tmpPk || this.isPk) { mPlayer.setViewResizeMode(false); String url; @@ -1031,6 +1033,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (userinputStreamList1.size() == 0) { //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setStreamType(RCRTCStreamType.NORMAL); ((RCRTCVideoInputStream) stream).setVideoView(remoteView); ((RCRTCVideoInputStream) stream).setVideoFrameListener(new IRCRTCVideoInputFrameListener() { @Override @@ -1040,7 +1043,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { "timestampNs:" + videoFrame.getTimestampNs() + "\n" + "分辨率:" + videoFrame.getBuffer().getHeight() + "x" + videoFrame.getBuffer().getWidth() + "\n" + "当前时间:" + new SimpleDateFormat("HH:mm:ss", Locale.CHINA).format(new Date()) + "\n"; - System.out.println("debugText = " + debugText); + Log.d("ry", "onFrame: " + debugText); new Handler(Looper.getMainLooper()).post(() -> { debugView.setText(debugText);