I see the question already asked here:
AirPods not working as an input source for Voice Recorder App
I've checked in with this thread but no response.
But, does anyone know if/why AVAudioRecorder might not be able to use the AirPods as an input device for recording audio in an app? I have audio recording working through the builtin mics as well as with other BT devices (Beats, cheapo BT speaker phone thing, etc.) but when working with the AirPods I'm unable to capture the audio.
In addition when about to record, I'm looping through the available inputs and forcing the input to be the BT device (see code below) in this case the AirPods. Again, works for all other BT devices except the AirPods.
Thoughts? Any guidance on what we're doing wrong here would be great. This has been maddening.
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord withOptions:audioSession.categoryOptions|AVAudioSessionCategoryOptionAllowBluetooth
error:&error];
[audioSession setActive:YES error:nil];
NSLog(@"Data sources: %@", [audioSession availableInputs]);
// Data sources: ("<AVAudioSessionPortDescription: 0x1706071b0, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Bottom>",
"<AVAudioSessionPortDescription: 0x170611bd0, type = BluetoothHFP; name = DanU2019s AirPods; UID = 50:32:37:E0:90:37-tsco; selectedDataSource = (null)>"
for (AVAudioSessionPortDescription *desc in [audioSession availableInputs]){
NSLog(@"Port desc: %@", desc.portType);
// Loop: 1) Port desc: MicrophoneBuiltIn
// 2) Port desc: BluetoothHFP
if (desc.portType == AVAudioSessionPortBluetoothHFP) {
NSLog(@"Trying to change preferred input");
NSError *error;
BOOL didSet = [audioSession setPreferredInput:desc error:&error];
NSString *didSetString = didSet ? @"True" : @"False";
NSLog(@"Post change preferred input: %@, error: %@", didSetString, error);
// Post change preferred input: True, error: (null)
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…