7

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.

zyeek
  • 1,277
  • 12
  • 27
  • 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 Jun 05 '17 at 00:02

3 Answers3

4

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

Community
  • 1
  • 1
Partho Biswas
  • 2,290
  • 1
  • 24
  • 39
  • Seems it can be rather tedious to check for specific results or verify it actually works. But if I have no other choice then I suppose it is what I got. – zyeek Mar 29 '17 at 21:31
  • 2
    If you record audio on simulator using AVAudioRecorder, it works just fine! So the simulator does have access to the microphone. There must be different reason. – bojan Jan 25 '21 at 01:39
3

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

OthmanT
  • 223
  • 3
  • 13
3

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

if let captureDevice = AVCaptureDevice.default(for: AVMediaType.audio) {
  // allocate AVCaptureDevice
}
Kathiresan Murugan
  • 2,783
  • 3
  • 23
  • 44