小编典典

通过没有快门声的 captureStillImageAsynchronouslyFromConnection 捕获图像 [重复]

all

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


阅读 104

收藏
2022-03-18

共1个答案

小编典典

我曾经使用此代码来捕获 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];

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

在此处输入图像描述

然后我将此声音保存为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

2022-03-18