Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable speakers on android and iOS #32

Open
himanshux22 opened this issue Oct 11, 2019 · 4 comments
Open

How to enable speakers on android and iOS #32

himanshux22 opened this issue Oct 11, 2019 · 4 comments

Comments

@himanshux22
Copy link

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
Copy link
Author

himanshux22 commented Oct 13, 2019

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
Copy link

@himanshux22 Any idea how to do it for iOS?

@himanshux22
Copy link
Author

himanshux22 commented Jun 1, 2020

@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
Copy link

@himanshux22 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants