Linphone SDK - 如何打开扬声器

时间:2016-12-06 10:14:39

标签: android linphone-sdk

我正在通过Linphone SDK构建视频聊天应用。

当有人"收到"一个视频通话,扬声器默认关闭,因此用户需要使用手机扬声器,一个用于通话,而不是扬声器。但是,与此同时,拨打电话的人默认开启扬声器。

LinphoneManager.getInstance().routeAudioToSpeaker();

我认为这是Linphone打开扬声器的代码,但实际上并非如此。

默认情况下,当用户接听视频通话时,如何打开扬声器?

3 个答案:

答案 0 :(得分:1)

LinphoneCore有两种方便的方法:

enableSpeaker(boolean)

muteMic(boolean)

只需在LinphoneManager中创建帮助函数:

public void enableVoice() {
    getLc().muteMic(false);
    getLc().enableSpeaker(true);
}

public void disableVoice() {
    getLc().muteMic(true);
    getLc().enableSpeaker(false);
}

如果您无法访问LinphoneManager,则上述功能应致电:

LinphoneManager.getLc().{method_call};

答案 1 :(得分:0)

private AudioManager mAudioManager;

...

public LinphoneMiniManager(Context c) {
        mContext = c;
        mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));

        mAudioManager.setSpeakerphoneOn(true);
...

答案 2 :(得分:0)

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
            }*/
        }
    }