Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVFoundation, how to turn off the shutter sound when captureStillImageAsynchronouslyFromConnection?

I am trying to capture an image during a live preview from the camera, by AVFoundation captureStillImageAsynchronouslyFromConnection. So far the program works as expected. However, how can I mute the shutter sound?

like image 445
ohho Avatar asked Dec 09 '10 17:12

ohho


People also ask

How do I turn off my camera shutter sound?

Step 1: In your phone's main menu and tap the Camera icon, as you would to take a picture. Step 2: Locate the Camera Settings — usually a gear icon somewhere at the top of the window. Step 3: Find an option that says Shutter Sound, Camera Sounds, or something similar.


1 Answers

I used this code once to capture iOS default shutter sound (here is list of sound file names https://github.com/TUNER88/iOSSystemSoundsLibrary):

NSString *path = @"/System/Library/Audio/UISounds/photoShutter.caf"; NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSData *data = [NSData dataWithContentsOfFile:path]; [data writeToFile:[docs stringByAppendingPathComponent:@"photoShutter.caf"] atomically:YES]; 

Then I used third-party app to extract photoShutter.caf from Documents directory (DiskAid for Mac). Next step I opened photoShutter.caf in Audacity audio editor and applied inversion effect, it looks like this on high zoom:

enter image description here

Then I saved this sound as photoShutter2.caf and tried to play this sound right before captureStillImageAsynchronouslyFromConnection:

static SystemSoundID soundID = 0; if (soundID == 0) {     NSString *path = [[NSBundle mainBundle] pathForResource:@"photoShutter2" ofType:@"caf"];     NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];     AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); } AudioServicesPlaySystemSound(soundID);  [self.stillImageOutput captureStillImageAsynchronouslyFromConnection: ... 

And this really works! I runs test several times, every time I hear no shutter sound :)

You can get already inverted sound, captured on iPhone 5S iOS 7.1.1 from this link: https://www.dropbox.com/s/1echsi6ivbb85bv/photoShutter2.caf

like image 170
k06a Avatar answered Oct 14 '22 15:10

k06a