我知道如何将AVAudioSession设置为能够从蓝牙设备读取音频输入。我通过以下代码完成此任务:
NSError *error;
[[AVAudioSession sharedInstance] setActive:NO error:&error];
[self.audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
NSError *errorTwo;
[self.audioSession setActive:YES error:&errorTwo];
通过将选项设置为AVAudioSessionOptionAllowBlueTooth,我可以设置它。但是,我正试图让它与录像机一起工作,我正在努力让这个工作。
我将发布从AVCaptureSession开始的内容:
self.captureSession = [AVCaptureSession new];
NSError *error;
[[AVAudioSession sharedInstance] setActive:NO error:&error];
self.captureSession.automaticallyConfiguresApplicationAudioSession = YES;
self.captureSession.automaticallyConfiguresApplicationAudioSession = true;
[self.audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
NSError *errorTwo;
[self.audioSession setActive:YES error:&errorTwo];
[self addAudioCapture];
AVCaptureDevice *audioInputDevice = [self audioDevice];
- (BOOL)addAudioCapture
{
AVCaptureDevice *audioInputDevice = [self audioDevice];
DLog(@"AUDIO INPUT DEVICE: %@", [audioInputDevice description]);
AVCaptureDeviceInput *audioIn = [[AVCaptureDeviceInput alloc] initWithDevice:audioInputDevice error:nil];
if ([self.captureSession canAddInput:audioIn])
{
[self.captureSession addInput:audioIn];
}
else
{
return NO;
}
self.audioOut = [[AVCaptureAudioDataOutput alloc] init];
dispatch_queue_t audioCaptureQueue = dispatch_queue_create("Audio Capture Queue", DISPATCH_QUEUE_SERIAL);
[self.audioOut setSampleBufferDelegate:self queue:audioCaptureQueue];
if ([self.captureSession canAddOutput:self.audioOut])
{
[self.captureSession addOutput:self.audioOut];
}
else
{
return NO;
}
self.audioConnection = [self.audioOut connectionWithMediaType:AVMediaTypeAudio];
return YES;
}
- (AVCaptureDevice *)audioDevice
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
if ([devices count] > 0)
{
return [devices objectAtIndex:0];
}
return nil;
}
然而,我面临的问题是audioInputDevice始终是iPhone麦克风。我已经确认我的蓝牙设备与我的手机配对,我已经编写了一个单独的应用程序来测试我当前正在使用的输入/输出,我可以确认iPhone可以读取蓝牙设备。但是,在我正在工作的主应用程序中,我无法设置它。任何有关如何实现这一目标的提示或建议将不胜感激。