优化switchMic
This commit is contained in:
@@ -3017,13 +3017,13 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
}
|
||||
|
||||
|
||||
private var currentMicState: Int = -1 // -1 未知,1 开,2 关
|
||||
private val micExecutor = Executors.newSingleThreadExecutor()
|
||||
/**
|
||||
* 设置是否打开麦克风
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
private var currentMicState: Int = -1 // -1 未知,1 开,2 关
|
||||
|
||||
fun switchMic(type: Int) {
|
||||
logIn("switchMic-${type}-")
|
||||
// ====== 1. 状态去重(非常关键) ======
|
||||
@@ -3031,40 +3031,22 @@ class RoomActivity : BaseMvpActivity<RoomPresenter?, ActivityRoomBinding?>(),
|
||||
return
|
||||
}
|
||||
currentMicState = type
|
||||
|
||||
// ====== 2. UI 只做 UI ======
|
||||
if (type == 1) {
|
||||
mBinding?.ivMic?.setImageResource(
|
||||
com.xscm.moduleutil.R.mipmap.room_microphone
|
||||
)
|
||||
mBinding!!.ivMic.setImageResource(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
|
||||
} else {
|
||||
mBinding?.ivMic?.setImageResource(
|
||||
com.xscm.moduleutil.R.mipmap.room_microphone_off
|
||||
)
|
||||
mBinding!!.ivMic.setImageResource(com.xscm.moduleutil.R.mipmap.room_microphone_off)
|
||||
AgoraManager.getInstance()
|
||||
.setLocalAudioEnabled(false, SpUtil.getUserId().toString() + "")
|
||||
isSwith = true
|
||||
isMute(1)
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user