I'm trying to capture audio, using the method in this question; with AVCaptureSession and AVCaptureAudioDataOutput. This seems to work fine with 1 inconvenience: it doesn't work in the simulator. Both AVAudioRecorder, and the good old SpeakHere demo app, work fine in the simulator, using the internal microphone on my MacBook Pro.
Problem is that [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]
gives null
in the simulator, so subsequent code fails with the message (when it tries to add null
as input to the AVCaptureSession):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Can't add <AVCaptureDeviceInput: 0x9138b40 [(null)]> because the device does not support AVCaptureSessionPresetHigh. Use -[AVCaptureDevice supportsAVCaptureSessionPreset:].'
Is there an easy way to get this to work in the simulator?
The
AVCaptureDevice
class is not implemented on the simulator (as of this writing at least, maybe it will change in the future).Try e.g.
which will produce an empty list on the simulator (but will list all capture devices if compiled and run on a real iDevice).
This kind of functionality needs to be tested on a real device anyway (due to the hardware detail dependency, such as latency and sample formats supported), so for testing purposes it is not that important to have device support in the simulator. But it would indeed be nice to have it for demo purposes.
To have a demo running on the simulator, maybe you can mock the capture input. If you really want to spend some time on it, maybe you can fallback on the
AVAudioRecorder
for the simulator (I never used AVAudioRecorder, so I can't tell if it does or does not work on the simulator, but from your question I read that it does).