Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to access the default camera shutter sound used by the iPhone

Right now when a user presses a button I play a custom camera shutter sound.

However, if possible, I would much rather just use the camera shutter sound that plays by default whenever you take a photo using your iPhone.

Is there a way that I can access and use the default iPhone camera shutter sound? And if yes, then where is it actually located?

I need to figure out it's file path so that I can use it with the code below and just change the input for pathForResource:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"shutter" ofType: @"wav"];

    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];

    self.myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

    [self.myAudioPlayer play];

Thanks for the help.

like image 608
user3344977 Avatar asked Apr 03 '14 22:04

user3344977


1 Answers

AudioServicesPlaySystemSound(1108);

Based on: Are there any other iOS system sounds available other than 'tock'? and http://iphonedevwiki.net/index.php/AudioServices

For 2016 ....

    if #available(iOS 9.0, *) {
        AudioServicesPlaySystemSoundWithCompletion(SystemSoundID(1108), nil)
    } else {
        AudioServicesPlaySystemSound(1108)
    }
like image 127
stevesliva Avatar answered Sep 19 '22 15:09

stevesliva