Listen to iPhone camera shutter sound when a button is pressed

How to play shutter sound from iPhone at the touch of a button?

+5
source share
4 answers

You can use a AudioToolboxpure magic number 1108as follows:

Swift:

import AudioToolbox
AudioServicesPlaySystemSound(1108)

Objective-C:

#import <AudioToolbox/AudioToolbox.h>
AudioServicesPlaySystemSound(1108);

Here is a complete list of these pure magic identifiers .

+8
source

1) Internet search for a camera shutter file. You can trim this if it's a little long using the .wav editor http://www.freesound.org/people/Nathan_Lomeli/sounds/79190/

2) shutter.wav .

3) .h

@interface  myViewController : UIViewController {
    SystemSoundID SoundID;
}

4) View "viewDidLoad":

  //load a sound wav file to use for the shutter
NSURL *buttonURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"shutter" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);

5) button_click:

   //play then shutter.wav sound
AudioServicesPlaySystemSound(SoundID);
+7

, , ObjC , Monotouch .

AVAudioPlayer AV- - .

, documentation , Apple

AVAudioPlayer , . , -, WAV-, Google.

, , , , .

0
source

some sounds that can be selected in this place: /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds / System / Library / Sounds

0
source

All Articles