From fe29d307a90f297280afa8c84cfdf25cb4067c77 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 15 Mar 2023 15:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9E=E9=BA=A6=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B050007=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=87=BA=E7=8E=B0=E8=AF=A5=E9=94=99=E8=AF=AF=E6=97=B6?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E7=A6=BB=E5=BC=80=E6=88=BF=E9=97=B4=E5=90=8E?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E5=8A=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/views/LivePlayRyViewHolder.java | 124 +++++++++++------- 1 file changed, 73 insertions(+), 51 deletions(-) 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 aef91f2bc..fc1c06205 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -123,6 +123,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private TextView debugView; private LiveExoPlayerManager mPlayer; private boolean isPk = false; + private boolean userJoinLinkMic = false;//用户是否已加入房间 //0未申请1申请中2连麦中 RCRTCRoom rcrtcRoom; @@ -734,6 +735,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { @Override public void onSuccess() { + userJoinLinkMic = false; Log.e("ry", "退出多人房间成功"); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { @@ -883,6 +885,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void UsertoRY() { userinputStreamList.clear(); Log.e("ry", "主播同意了UsertoRY"); + if (userJoinLinkMic) {//已经在房间内,不再joinRoom直接去连麦 + subscribeMic(rcrtcRoom); + return; + } RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() // 根据实际场景,选择音视频直播:LIVE_AUDIO_VIDEO 或音频直播:LIVE_AUDIO .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) @@ -893,59 +899,33 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void onSuccess(RCRTCRoom data) { + userJoinLinkMic = true; rcrtcRoom = data; - runOnUiThread(new Runnable() { - @Override - public void run() { - RCRTCEngine.getInstance().enableSpeaker(true); - //遍历远端用户发布的资源列表 - for (RCRTCInputStream stream : data.getLiveStreams()) { - if (stream.getMediaType() == RCRTCMediaType.VIDEO) { - //暂停播放 - mPlayer.stop(); - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - - //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 - RCRTCVideoView remoteView = new RCRTCVideoView(contexts); - ((RCRTCVideoInputStream) stream).setVideoView(remoteView); - //todo 本demo只演示添加1个远端用户的视图 - remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - ry_view.addView(remoteView); - Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); - } - userinputStreamList.add(stream); - } - rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { - - @Override - public void onFailed(RTCErrorCode errorCode) { - Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); - - } - - @Override - public void onSuccess() { - Log.e("ry", "订阅资源成功"); -// new Handler().postDelayed(new Runnable() { -// @Override -// public void run() { - toMic(); -// } -// }, 3000); - - } - }); - } - }); - + subscribeMic(data); } @Override public void onFailed(RTCErrorCode errorCode) { Log.e("ry", LiveActivity.mLiveUid + errorCode + ""); - ToastUtil.show("房间失败" + errorCode); + if (errorCode.getValue() == 50007) {//userJoinLinkMic可能失效,直接leaveRoom + userJoinLinkMic = false; + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + ToastUtil.show("离开房间成功"); + UsertoRY(); + } + }); + }else{ + ToastUtil.show("房间失败" + errorCode); + } } }); @@ -953,6 +933,53 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } + private void subscribeMic(RCRTCRoom data) { + runOnUiThread(new Runnable() { + @Override + public void run() { + RCRTCEngine.getInstance().enableSpeaker(true); + //遍历远端用户发布的资源列表 + for (RCRTCInputStream stream : data.getLiveStreams()) { + if (stream.getMediaType() == RCRTCMediaType.VIDEO) { + //暂停播放 + mPlayer.stop(); + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + + //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 + RCRTCVideoView remoteView = new RCRTCVideoView(contexts); + ((RCRTCVideoInputStream) stream).setVideoView(remoteView); + //todo 本demo只演示添加1个远端用户的视图 + remoteView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); + ry_view.addView(remoteView); + Log.e("ry", stream.getMediaType() + "rcrtcOtherRoom成功 :" + data.getLiveStreams().size()); + } + userinputStreamList.add(stream); + } + rcrtcRoom.getLocalUser().subscribeStreams(userinputStreamList, new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", userinputStreamList.size() + LiveActivity.mLiveUid + "订阅失败" + errorCode.toString()); + + } + + @Override + public void onSuccess() { + Log.e("ry", "订阅资源成功"); +// new Handler().postDelayed(new Runnable() { +// @Override +// public void run() { + toMic(); +// } +// }, 3000); + + } + }); + } + }); + } + /** * 主房间事件监听 * 详细说明请参考文档:https://www.rongcloud.cn/docs/api/android/rtclib_v4/cn/rongcloud/rtc/api/callback/IRCRTCRoomEventsListener.html @@ -1246,9 +1273,4 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } - - - - - }