我正在try 捕捉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,并应用反转效果,在高变焦时看起来是这样的:

在此处输入图像描述

然后我将此声音保存为photoShutter2.caf,并try 在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相关问答推荐

更新Flutter项目时出错:CocoaPods找不到pod webview_flutter_wkwebview的兼容版本""

为什么导航栏在与Style.Page的选项卡栏一起使用时停止工作?

SwiftData在获取值时应用程序崩溃:线程1:EXC_BREAKPOINT(代码=1,子代码=0x101e8303c)

用于HDR显示的CI上下文选项

BezierPath 中绘制图像形状轮廓的算法(Canny 边缘检测器)

封装 Swift 导入

使用 Objective-C 创建 iOS 框架

不使用故事板创建 iMessage 应用程序

当 Swift 枚举具有 any existential 作为其关联值之一时,我如何使它符合 `Equatable`?

使用 JSONDecoder 解码的对象的打印输出有问题

SwiftUI:通过Sheet将数据添加到Realm DB时视图不更新

.onAppear() 函数不适用于 NavigationLink

使用 CIImage 支持的 UIImage 设置 UIImageView 时发生罕见的崩溃

通过按钮打开 AppStore

Select UITableViewCell 时 UIView backgroundColor 消失

UICollectionView - 动态单元格高度?

iOS Swift - 获取当前本地时间和日期时间戳

使用 Chrome DevTools 调试 iOS 6+7 Mobile Safari

如果已安装,则重定向到应用程序,否则重定向到 App Store

UINavigationBar - 以编程方式设置标题?