我拉过新代码了,
由于我UI的状态取的是 didAudioDeviceChanged
函数的回调的值,所有会有bug.
虽然你们demo跑起来时 ui的扬声器按钮状对上了(都是扬声器)。但是 如果我在reciveCall 函数中给这个callsession 设置 callback ,在收到来电时,会立刻触发一次 didAudioDeviceChanged 函数, 此时默认是听筒,然后你们 的AvAudioManager 类会设置 为扬声器,设置成功后,不会再次触发 didAudioDeviceChanged
函数,
public void onReceiveCall(AVEngineKit.CallSession session) {
ChatManager.Instance().getMainHandler().postDelayed(() -> {
AVEngineKit.CallSession callSession = AVEngineKit.Instance().getCurrentSession();
if (callSession == null || callSession.getState() == AVEngineKit.CallState.Idle) {
return;
}
// callSession.setVideoCapturer(new UVCCameraCapturer());
List<String> participants = callSession.getParticipantIds();
if (participants == null || participants.isEmpty()) {
return;
}
Conversation conversation = callSession.getConversation();
if (conversation == null) {
return;
}
if (conversation.type == Conversation.ConversationType.Single) {
//Intent intent = new Intent(WfcIntent.ACTION_VOIP_SINGLE);
Intent intent = new Intent(application, SingleCallActivity.class);
startActivity(application, intent);
} else {
//Intent intent = new Intent(WfcIntent.ACTION_VOIP_MULTI);
Intent intent = new Intent(application, MultiCallActivity.class);
startActivity(application, intent);
}
VoipCallService.start(application, false);
if (avEngineCallback != null) {
avEngineCallback.onReceiveCall(AVEngineKit.Instance().getCurrentSession());
}
}, 200);
}
上面你们原来的代码会少收到这一次的 didAudioDeviceChanged,
如果在收到 onReceiveCall 的时候立刻给这个session这个callback,就会出现我的问题,
@Override
public void onReceiveCall(AVEngineKit.CallSession session) {
Log.d(TAG, "onReceiveCall: ");
session.setCallback(new AVEngineKit.CallSessionCallback() {
//省略代码
}
//省略代码,无改动
}