【发布时间】:2017-10-06 18:54:42
【问题描述】:
我在这里看到了已经问过的问题:
AirPods not working as an input source for Voice Recorder App
我已经签入了这个帖子,但没有任何回应。
但是,有谁知道 AVAudioRecorder 是否/为什么无法将 AirPods 用作在应用程序中录制音频的输入设备?我通过内置麦克风以及其他 BT 设备(Beats、cheapo 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)
}
}
【问题讨论】:
标签: ios objective-c bluetooth avaudiosession