修复连麦时可能出现50007问题,出现该错误时尝试离开房间后重试加入

This commit is contained in:
zlzw 2023-03-15 15:49:56 +08:00
parent 06dddb5273
commit fe29d307a9

View File

@ -123,6 +123,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private TextView debugView; private TextView debugView;
private LiveExoPlayerManager mPlayer; private LiveExoPlayerManager mPlayer;
private boolean isPk = false; private boolean isPk = false;
private boolean userJoinLinkMic = false;//用户是否已加入房间
//0未申请1申请中2连麦中 //0未申请1申请中2连麦中
RCRTCRoom rcrtcRoom; RCRTCRoom rcrtcRoom;
@ -734,6 +735,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
userJoinLinkMic = false;
Log.e("ry", "退出多人房间成功"); Log.e("ry", "退出多人房间成功");
new Handler(Looper.getMainLooper()).post(new Runnable() { new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() { public void run() {
@ -883,6 +885,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void UsertoRY() { public void UsertoRY() {
userinputStreamList.clear(); userinputStreamList.clear();
Log.e("ry", "主播同意了UsertoRY"); Log.e("ry", "主播同意了UsertoRY");
if (userJoinLinkMic) {//已经在房间内不再joinRoom直接去连麦
subscribeMic(rcrtcRoom);
return;
}
RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create() RCRTCRoomConfig roomConfig = RCRTCRoomConfig.Builder.create()
// 根据实际场景选择音视频直播LIVE_AUDIO_VIDEO 或音频直播LIVE_AUDIO // 根据实际场景选择音视频直播LIVE_AUDIO_VIDEO 或音频直播LIVE_AUDIO
.setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO) .setRoomType(RCRTCRoomType.LIVE_AUDIO_VIDEO)
@ -893,59 +899,33 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
@Override @Override
public void onSuccess(RCRTCRoom data) { public void onSuccess(RCRTCRoom data) {
userJoinLinkMic = true;
rcrtcRoom = data; rcrtcRoom = data;
runOnUiThread(new Runnable() { subscribeMic(data);
@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);
}
});
}
});
} }
@Override @Override
public void onFailed(RTCErrorCode errorCode) { public void onFailed(RTCErrorCode errorCode) {
Log.e("ry", LiveActivity.mLiveUid + 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 * 详细说明请参考文档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 {
} }
} }