ginger ginger - 1 month ago 8
iOS Question

How to sound iPhone's default shutter sound

Currently, I use AVFoundation's AVCaptureVideoDataOutput to create a camera application.
It is a specification that I tap the shooting button and save the necessary frame as a still image on the camera roll.
(I do not save movies.)
About the shutter sound of the iPhone, I ask you a question.

・Question
What kind of coding should I do in order to sound the iPhone's default shutter sound?

At first, I created a camera application without shutter sound using AVCaptureVideoDataOutput.
Next, I would like to create a camera with shutter sound using AVCaptureVideoDataOutput.

I do not know how to sound the iPhone's default shutter sound while using AVCaptureVideoDataOutput.

Is there a way to forcibly sound the iPhone's default shutter sound?

■Supplement
xcode8.3.3
swift3.1
Deployment Target:10.2
I'd like to implement AVCaptureVideoDataOutput because I want to implement both movie shooting and still shooting in the future.

Answer Source

Yes,

use this:

AudioServicesPlaySystemSound(1108);

You can check all full sounds here:

Sounds

For a custom sound:

AVAudioPlayer *audioPlayer;
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Name of your audio file" 
                                                      ofType:@"type of your audio file example: mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];

Make sure you import

<AVFoundation/AVFoundation.h>