Brian
Brian

Reputation: 31302

Linphone SDK - how to turn on loud speaker

I am building a video chatting app via the Linphone SDK.

There is an issue that when someone "receives" a video call, the loud speaker is off by default, so users need to use the phone speaker, the one used for phone call, rather than the loud speaker. However, at the same time, the one who gives the call has the loud speaker on by default.

LinphoneManager.getInstance().routeAudioToSpeaker();

I thought this is the code for which Linphone turns on loud speaker, but actually it's not.

How do I turn on loud speaker when users receive video calls by default?

Upvotes: 1

Views: 2730

Answers (3)

Anvar Quvandiqov
Anvar Quvandiqov

Reputation: 289

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

Upvotes: 0

Daniel Ehrhardt
Daniel Ehrhardt

Reputation: 1032

private AudioManager mAudioManager;

...

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

        mAudioManager.setSpeakerphoneOn(true);
...

Upvotes: 0

R. Zagórski
R. Zagórski

Reputation: 20268

LinphoneCore has two handy method for that:

enableSpeaker(boolean)

muteMic(boolean)

Just create helper functions inside LinphoneManager:

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

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

If you don't have an access to LinphoneManager, then the functions above should call:

LinphoneManager.getLc().{method_call};

Upvotes: 2

Related Questions