We are using third party Audio/Video SDK in our Xamarin.Forms.iOSproject. Now problem is that by default audio comes in speaker mode, instead of ear-speaker. I found below code and using that audio is toggling in ear-speaker and speaker. but when I am on speaker then microphone is muted and when I am in ear-speaker then both are working. so my question is how to enable microphone in both case?
bool blIsOnEarSpeaker=false;
public void SetAudioSettingsForIOS()
{
var session=AVFoundation.AVAudioSession.SharedInstance();
AVFoundation.AVAudioSessionCategory objCategory= AVFoundation.AVAudioSessionCategory.Playback;
Foundation.NSError error = null;
if (blIsOnEarSpeaker==false)
{
objCategory=AVFoundation.AVAudioSessionCategory.PlayAndRecord;
blIsOnEarSpeaker=true;
error = session.SetCategory(objCategory);
}
else
{
objCategory=AVFoundation.AVAudioSessionCategory.Playback;
blIsOnEarSpeaker=false;
error = session.SetCategory(
objCategory
,AVFoundation.AVAudioSessionCategoryOptions.DefaultToSpeaker
);
}
error = session.SetActive(true);
}