Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureDevice is always null on simulator

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.

like image 392
zyeek Avatar asked Mar 29 '17 20:03

zyeek


3 Answers

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

like image 155
Partho Biswas Avatar answered Nov 12 '22 12:11

Partho Biswas


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

like image 29
OthmanT Avatar answered Nov 12 '22 11:11

OthmanT


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

if let captureDevice = AVCaptureDevice.default(for: AVMediaType.audio) {
  // allocate AVCaptureDevice
}
like image 3
Kathiresan Murugan Avatar answered Nov 12 '22 13:11

Kathiresan Murugan