BelledonneCommunications / linphone-xamarin

Linphone.org mirror for linphone-xamarin (git://git.linphone.org/linphone-xamarin.git)
https://www.linphone.org/
GNU General Public License v3.0
26 stars 21 forks source link

How to enable speakers on android and iOS #32

Open himanshux22 opened 5 years ago

himanshux22 commented 5 years ago

Hey, I was trying to route the audio to the speaker. But I am not getting any option to do so, I got an Enum AudioRoute with Earpiece and speaker option, but don't know how to use it.

Can anyone please tell me how to use AudioRoute Enum or how to use speaker for audio call.

himanshux22 commented 5 years ago

Update: For Android Do this:-

AudioManager am =(AudioManager)Application.Context.GetSystemService(Context.AudioService);
            am.Mode = Mode.InCall;
            am.SpeakerphoneOn = true;
            am.SetStreamVolume(Stream.VoiceCall, am.GetStreamMaxVolume(Stream.VoiceCall), VolumeNotificationFlags.ShowUi);
MrAndrewAu commented 4 years ago

@himanshux22 Any idea how to do it for iOS?

himanshux22 commented 4 years ago

@MrAndrewAu

@himanshux22 Any idea how to do it for iOS? ///Here are the functions I used for ios speaker on/off

 static void SetIOSAudioSettingsOn()
        {
            try
            {
                /**/
                NSError error = AVFoundation.AVAudioSession.SharedInstance().SetCategory(AVFoundation.AVAudioSessionCategory.PlayAndRecord, AVFoundation.AVAudioSessionCategoryOptions.DefaultToSpeaker);

                if (error == null)
                {
                    if (AVFoundation.AVAudioSession.SharedInstance().SetMode(AVFoundation.AVAudioSession.ModeVoiceChat, out error))
                    {
                        if (AVFoundation.AVAudioSession.SharedInstance().OverrideOutputAudioPort(AVFoundation.AVAudioSessionPortOverride.Speaker, out error))
                        {
                            error = AVFoundation.AVAudioSession.SharedInstance().SetActive(true);

                            if (error != null)
                            {
                                //  Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot set active"));
                            }
                        }
                        else
                        {
                            // Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot override output audio port"));
                        }
                    }
                    else
                    {
                        //Logger.Log(new Exception("Cannot set mode"));
                    }
                }
                else
                {
                    //Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot set category"));
                }
            }
            catch (Exception ex)
            {

            }
        }

        static void SetIOSAudioSettingsOFF()
        {
            try
            {
                /**/
                NSError error = AVFoundation.AVAudioSession.SharedInstance().SetCategory(AVFoundation.AVAudioSessionCategory.PlayAndRecord, AVFoundation.AVAudioSessionCategoryOptions.AllowBluetooth);
                var audioSession = AVAudioSession.SharedInstance();
                if (error == null)
                {
                    if (AVFoundation.AVAudioSession.SharedInstance().SetMode(AVFoundation.AVAudioSession.ModeVoiceChat, out error))
                    {
                        if (AVFoundation.AVAudioSession.SharedInstance().OverrideOutputAudioPort(AVFoundation.AVAudioSessionPortOverride.None, out error))
                        {
                            error = AVFoundation.AVAudioSession.SharedInstance().SetActive(true);

                            if (error != null)
                            {
                                //  Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot set active"));
                            }
                        }
                        else
                        {
                            // Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot override output audio port"));
                        }
                    }
                    else
                    {
                        //Logger.Log(new Exception("Cannot set mode"));
                    }
                }
                else
                {
                    //Logger.Log(new Exception(error?.LocalizedDescription ?? "Cannot set category"));
                }
            }
            catch (Exception ex)
            {

            }
        }
MrAndrewAu commented 4 years ago

@himanshux22 Thank you!