ios - AVFoundation,如何关闭captureStillImageAsynchronouslyFromConnection时的快门声?

标签 ios iphone cocoa-touch camera avfoundation

我正在尝试通过 AVFoundation 在相机的实时预览期间捕捉图像 captureStillImageAsynchronouslyFromConnection .到目前为止,该程序按预期工作。但是,如何使快门声音静音?

最佳答案

我曾使用此代码捕获 iOS 默认快门声音(这里是声音文件名列表 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];

然后我使用第三方应用程序从 Documents 目录 (DiskAid for Mac) 中提取 photoShutter.caf。下一步,我在 Audacity 音频编辑器中打开了 photoShutter.caf 并应用了反转效果,它在高倍率下看起来像这样:

enter image description here

然后我将这个声音保存为 photoShutter2.caf 并尝试在 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:
...

这真的很管用!我运行了几次测试,每次我都没有听到快门声:)

您可以从以下链接获得已经倒置的声音,在 iPhone 5S iOS 7.1.1 上捕获:https://www.dropbox.com/s/1echsi6ivbb85bv/photoShutter2.caf

关于ios - AVFoundation,如何关闭captureStillImageAsynchronouslyFromConnection时的快门声?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4401232/

相关文章:

ios - iOS 7 和 iOS 8 中的动态单元格高度 - 我只能在 iOS 7 中支持 heightForRowAtIndexPath 吗?

ios - 如何在 Store Kit 应用内购买中测试取消订阅?

ios - 弹出框内的 UISearchDisplayController - 取消搜索时动画效果不佳

iphone - 如何访问 NSString 中的第 n 个字符?

iphone - ffmpeg 在 iOS 上的使用

ios - 如何从开始播放AVAudioplayer?

iphone - 如何获得两地之间的行程?

ios - 搜索结果中的 Swift 搜索结果 Controller 转至另一个 View Controller

iphone - NavigationController 和 ToolBar 问题

iphone - 自动标签切换