I am trying to access the microphone using AVCaptureDevice and handle the incoming sound, but the return value from
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]always is nil.
I found this question where it looks like they had the same problem, but I obviously did not resolve the sandbox, and I added the .plist file with key com.apple.security.device.microphoneand value YES, so I think I should have access to the microphone.
Here is my code
- (void)configureAudioSession
{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:&error];
_captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *input = [[AVCaptureDeviceInput alloc] initWithDevice:device error:nil];
if (input == nil)
{
NSLog(@"nil input");
}
[_captureSession addInput:input];
AVCaptureAudioDataOutput *output = [[AVCaptureAudioDataOutput alloc] init];
dispatch_queue_t queue = dispatch_queue_create("Callback", DISPATCH_QUEUE_SERIAL);
[output setSampleBufferDelegate:self queue:queue];
[_captureSession addOutput:output];
[_captureSession startRunning];
}
source
share