From ec40f8fa0de4be19174977c5c62e85d797632793 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 24 Nov 2022 16:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=B8=8B=E9=BA=A6=E6=97=B6?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=9E=8D=E4=BA=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/utils/MicStatusManager.java | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java b/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java index e354a2765..1698aa54e 100644 --- a/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java +++ b/live/src/main/java/com/yunbao/live/utils/MicStatusManager.java @@ -1,14 +1,22 @@ package com.yunbao.live.utils; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.activity.LiveActivity; import org.greenrobot.eventbus.EventBus; +import cn.rongcloud.rtc.api.RCRTCEngine; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.api.callback.IRCRTCSwitchRoleCallback; +import cn.rongcloud.rtc.base.RTCErrorCode; + /** * 统一管理连麦状态 */ @@ -67,9 +75,54 @@ public class MicStatusManager { @Override public void onSuccess(int code, String msg, String[] info) { Log.e("ry", code + "退出多人"); - clear(); + RCRTCEngine.getInstance().getRoom().getLocalUser().switchToAudience(new IRCRTCSwitchRoleCallback() { + + /** + * 当切换失败且SDK处于无法回退状态时回调,该角色已经无法使用当前角色继续进行音视频。 + * SDK内部会退出房间并清理所有资源,该用户只能重新加入房间才能继续音视频。 + */ + @Override + public void onKicked() { + + } + + @Override + public void onSuccess() { + Log.e("ry", "下麦成功"); + // 该用户切换为观众成功,可以以观众身份进行音视频 + //退出rtc播放 + RCRTCEngine.getInstance().leaveRoom(new IRCRTCResultCallback() { + @Override + public void onSuccess() { + Log.e("ry", "退出多人房间成功"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + public void run() { + MicStatusManager.getInstance().clear(); + ToastUtil.show("已成功退出語音連麥"); + } + }); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", errorCode + "退出多人房间成功"); + + } + }); + + } + + /** + * 当切换失败且不影响当前角色继续音视频时回调 + * @param errorCode 失败错误码 + */ + @Override + public void onFailed(RTCErrorCode errorCode) { + Log.e("ry", "下麦失败" + errorCode); + + } + }); } }); - EventBus.getDefault().post("endMic"); } }