Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioServicesPlaySystemSound while AVCaptureSession is active

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?

like image 268
Gabriele Petronella Avatar asked Jul 30 '13 20:07

Gabriele Petronella


1 Answers

Play the sound using AVAudioPlayer instead.

like image 70
sc0rp10n Avatar answered Oct 22 '22 21:10

sc0rp10n