2017-10-06 109 views
0

/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) 
    } 
} 

回答

1

原來我們不得不處理正在設置的類別。由於我們在設置各種藍牙輸出設備時遇到的問題,並且除非我們準備好錄製時,將音頻類別設置爲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

0

我覺得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