I'm developing a recording application and I want to play a sound when the recording starts.
Unfortunately it appears that since iOS 5 it's not possible to play a system sound when a AVCaptureSession
with an audio device is active.
Here's the relevant part of the code I'm using
- (void)viewDidLoad {
[super viewDidLoad];
NSURL * soundURL = [[NSBundle mainBundle] URLForResource:@"recording-starts" withExtension:@"aif"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, &_recStartSound);
//...
if ([self.captureManager setupSession]) {
// ...
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.captureManager.session startRunning];
});
// ...
}
}
Later on, I just call AudioServicesPlaySystemSound(_recStartSound)
and nothing goes on.
However if I make the same call before the session setup, the sound plays as expected.
I found this bug report, which is exactly relevant to my problem, as well as this and this question, but I couldn't find any workaround in none of them.
How can I play a short sound right before starting the AV recording?
Play the sound using AVAudioPlayer instead.
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