Open himanshux22 opened 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);
@himanshux22 Any idea how to do it for iOS?
@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)
{
}
}
@himanshux22 Thank you!
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.