/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)
}
}
謝謝。我會仔細研究一下,看看它是否有幫助。 – djneely