我正在通过 Linphone SDK 构建一个视频聊天应用程序。
存在一个问题,当有人“接听”视频通话时,扬声器默认关闭,因此用户需要使用电话扬声器,即用于通话的扬声器,而不是扬声器。但是,同时,拨打电话的人默认打开扬声器。
LinphoneManager.getInstance().routeAudioToSpeaker();
我以为这是 Linphone 打开扬声器的代码,但实际上不是。
用户默认接听视频电话,如何开启外放?
我正在通过 Linphone SDK 构建一个视频聊天应用程序。
存在一个问题,当有人“接听”视频通话时,扬声器默认关闭,因此用户需要使用电话扬声器,即用于通话的扬声器,而不是扬声器。但是,同时,拨打电话的人默认打开扬声器。
LinphoneManager.getInstance().routeAudioToSpeaker();
我以为这是 Linphone 打开扬声器的代码,但实际上不是。
用户默认接听视频电话,如何开启外放?
LinphoneCore
有两种方便的方法:
只需在里面创建辅助函数LinphoneManager
:
public void enableVoice() {
getLc().muteMic(false);
getLc().enableSpeaker(true);
}
public void disableVoice() {
getLc().muteMic(true);
getLc().enableSpeaker(false);
}
如果您无权访问LinphoneManager
,则上述函数应调用:
LinphoneManager.getLc().{method_call};
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
....
btnSpeaker.setOnClickListener {
mIsSpeakerEnabled = !mIsSpeakerEnabled
it.isSelected = mIsSpeakerEnabled
toggleSpeaker()
}
....
}
private fun toggleSpeaker() {
val currentAudioDevice = core.currentCall?.outputAudioDevice
val speakerEnabled = currentAudioDevice?.type == AudioDevice.Type.Speaker
for (audioDevice in core.audioDevices) {
if (speakerEnabled && audioDevice.type == AudioDevice.Type.Earpiece) {
core.currentCall?.outputAudioDevice = audioDevice
return
} else if (!speakerEnabled && audioDevice.type == AudioDevice.Type.Speaker) {
core.currentCall?.outputAudioDevice = audioDevice
return
}/* If we wanted to route the audio to a bluetooth headset
else if (audioDevice.type == AudioDevice.Type.Bluetooth) {
core.currentCall?.outputAudioDevice = audioDevice
}*/
}
}
private AudioManager mAudioManager;
...
public LinphoneMiniManager(Context c) {
mContext = c;
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mAudioManager.setSpeakerphoneOn(true);
...