1

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?

Brian
  • 30,156
  • 15
  • 86
  • 87

3 Answers3

2

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};
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
0
private AudioManager mAudioManager;

...

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

        mAudioManager.setSpeakerphoneOn(true);
...
Daniel Ehrhardt
  • 908
  • 7
  • 16
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
            }*/
        }
    }