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 目录(Mac 的 DiskAid)中提取 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/23758875/

相关文章:

ios - 将数字显示为字符串

iphone - UItableView删除行使用函数

ios - 在日/夜系统的着色层内创建 "light sources"

iphone - 是否可以根据国家/地区更改捆绑显示名称?

ios - UICollectionView 的弹性 header

iphone - 从Safari在iOS6中显示 native 推文对话

iPhone 演示帮助 : anyone know of a faster screen capture alternative to UIGetScreenImage()?

iphone - 返回时取消选择 TableView 行

ios - 在 iOS 应用程序中,如果计划触发计时器并且应用程序处于后台,我是否确定一旦应用程序再次进入前台,计时器就会触发?

ios - 具有多个项目和 Coca Pods 设置的 Xcode 工作区