7
votes

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.

3
I have been experiencing the same after upgrading it to iOS 10.3. The UIImagePickerControllerOriginalImage always returning null. I even try to implement "AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video)" and "Adding NSPhotoLibraryUsageDescription in info.plist" but still no luck - pampi

3 Answers

4
votes

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

3
votes

The simulator cannot take the Mac microphone as a source. You need to use a real device to test that.

3
votes

Simulator is not having mic and camera. So Check like and proceed

if let captureDevice = AVCaptureDevice.default(for: AVMediaType.audio) {
  // allocate AVCaptureDevice
}