I am trying to capture live microphone audio data.
I took the following from the apple example for AVCaptureSession
.
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
NSError *error = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
if (audioInput) {
[captureSession addInput:audioInput];
}
else {
// Handle the failure.
NSLog(@"ERROR");
}
audioCaptureDevice
and audioInput
are both null.
Yes, it should be. Because simulator doesn't have any microphone. You should always test any audio, video, rendering related task on a real device.
Take a look about Limitations of Testing in iOS Simulator
Hardware Limitations While most of the functionality of iOS devices can be simulated in iOS Simulator, there are some hardware features that must be tested directly on a device. The hardware features that cannot be simulated are:
Accelerometer
Gyroscope
Camera
Proximity
Sensor Microphone Input
The simulator cannot take the Mac microphone as a source. You need to use a real device to test that.
Simulator is not having mic and camera. So Check like and proceed
if let captureDevice = AVCaptureDevice.default(for: AVMediaType.audio) {
// allocate AVCaptureDevice
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With