We use Microphone in our app but we have some serious issues with it on iOS:
1) By default when activating a Microphone on iOS, the app freezes for a few noticeable moments;
2) We can fix #1 by checking “Prepare iOS for Recording” on PlayerSettings;
3) By doing #2, the default speaker is now the earphone speaker, which is undesirable. To fix this, we check “Force iOS Speakers when Recording”;
4) Due to #3, now Bluetooth phones and AirPlay stop working, which we can fix by calling the following native code when Mic is activated/deactivated:
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay
error:nil];
5) This solution brings us back to problem #1, which are the freezes on activating Microphone…
What is the proper way to handle this?
The requirements are:
- Don’t freeze app when microphone activates;
- Use built-mic (not Bluetooth)
- Support Bluetooth phones and AirPlay
I understand that it’s possible to pre-activate the microphone, but that would not be possible if we wished to ask permission just before the microphone is used for the first time.
Why is there nothing on Unity like Microphone.PrepareForRecording()
?
What configurations exactly do PlayerSettings’ “Prepare iOS for Recording
” and “Force iOS Speakers when Recording
” set?
I have searched on many topics (not only on this forum) but couldn’t find a conclusive way to fix this.