AVAudioRecorder与苹果Airpods

问题描述:

/AVAudioSession我看到这里已经提出这样的问题:AVAudioRecorder与苹果Airpods

AirPods not working as an input source for Voice Recorder App

我这个线程,但没有任何反应检查英寸

但是,有谁知道是否/为什么AVAudioRecorder可能无法使用AirPods作为输入设备在应用程序中录制音频?我通过内置麦克风以及其他BT设备(Beats,便携式BT扬声器电话等)进行录音,但使用AirPods时无法捕获音频。

另外,当要记录时,我循环访问可用输入并强制输入为BT设备(请参阅下面的代码),这种情况下为AirPods。再次,适用于除AirPods以外的所有其他BT设备。

想法?任何关于我们在这里做错的指导都会很棒。这一直令人生气。

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 = Dan\U2019s 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) 
    } 
} 

原来我们不得不处理正在设置的类别。由于我们在设置各种蓝牙输出设备时遇到的问题,并且除非我们准备好录制时,将音频类别设置为AVAudioSessionCategoryPlayback

每本叠后:AVAudioSession: Some Bluetooth devices are not working properly on my App

在上面的代码中,我们切换类别到AVAudioSessionCategoryRecord我们将要记录之前。虽然这适用于内置麦克风和其他蓝牙设备,但它不适用于AirPods。相反,将类别设置为AVAudioSessionCategoryPlayAndRecord可以让录制与AirPods一起使用。

然后,我仍然保持整个应用程序中用于音频回放的会话的仅回放类别。只有在即将录制音频时切换到PlayAndRecord。

附注:苹果公司并未将AirPods列为MFi设备。 https://mfi.apple.com/MFiWeb/getFAQ.action#1-1

我觉得AirPods是MFI(iPhone专用)配件,这意味着蓝牙通信会突破ExternalAccessory框架https://developer.apple.com/documentation/externalaccessory

这里是苹果的演示: https://developer.apple.com/library/content/samplecode/EADemo/Introduction/Intro.html

提示:协议名称必须放in Info.plist in UISupportedExternalAccessoryProtocols key

更多详细信息:https://mfi.apple.com/MFiWeb/getFAQ.action

+0

谢谢。我会仔细研究一下,看看它是否有帮助。 – djneely