优化switchMic

This commit is contained in:
2026-01-14 15:09:18 +08:00
parent f5b4dde3c6
commit e9ab535b2d

View File

@@ -3017,13 +3017,13 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
} }
private var currentMicState: Int = -1 // -1 未知1 开2 关
private val micExecutor = Executors.newSingleThreadExecutor()
/** /**
* 设置是否打开麦克风 * 设置是否打开麦克风
* *
* @param type * @param type
*/ */
private var currentMicState: Int = -1 // -1 未知1 开2 关
fun switchMic(type: Int) { fun switchMic(type: Int) {
logIn("switchMic-${type}-") logIn("switchMic-${type}-")
// ====== 1. 状态去重(非常关键) ====== // ====== 1. 状态去重(非常关键) ======
@@ -3031,40 +3031,22 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
return return
} }
currentMicState = type currentMicState = type
// ====== 2. UI 只做 UI ======
if (type == 1) { if (type == 1) {
mBinding?.ivMic?.setImageResource( mBinding!!.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone)
com.xscm.moduleutil.R.mipmap.room_microphone AgoraManager.getInstance()
) .setLocalAudioEnabled(true, SpUtil.getUserId().toString() + "")
isSwith = false
AgoraManager.getInstance().muteLocalAudioStream(false)
AgoraManager.getInstance().ClientRole(true)
CommonAppContext.getInstance().isMai = true CommonAppContext.getInstance().isMai = true
} else { } else {
mBinding?.ivMic?.setImageResource( mBinding!!.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone_off)
com.xscm.moduleutil.R.mipmap.room_microphone_off AgoraManager.getInstance()
) .setLocalAudioEnabled(false, SpUtil.getUserId().toString() + "")
isSwith = true
isMute(1)
CommonAppContext.getInstance().isMai = false CommonAppContext.getInstance().isMai = false
} }
// ====== 3. SDK 调用全部丢到后台线程 ======
micExecutor.execute {
try {
val agora = AgoraManager.getInstance()
val uid = SpUtil.getUserId().toString()
if (type == 1) {
agora.setLocalAudioEnabled(true, uid)
agora.muteLocalAudioStream(false)
agora.ClientRole(true)
isSwith = false
} else {
agora.setLocalAudioEnabled(false, uid)
isMute(1)
isSwith = true
}
} catch (e: Exception) {
e.printStackTrace()
}
}
} }
fun setPrivateRoomShowBottom() { fun setPrivateRoomShowBottom() {