?? iOS如何拍照静音-效果上可以完美解决
2020/4/27 23:03:59
本文主要是介绍?? iOS如何拍照静音-效果上可以完美解决,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
时间:2020年4月27日。
备注:Demo中已经完美解决,没什么问题。
原理:在即将播放声音时,释放声音资源
- 非网传的声波抵消
- 非截取视频流(像素差一些)
声波抵消时机不好掌握,一旦发生卡顿,极有可能播放两次声音,或者音频错位
注意:不适用StillImage
这种方式效果不佳,会产生奇怪的效果,而且API已经过时。
- (void)captureStillImageAsynchronouslyFromConnection:(AVCaptureConnection *)connection completionHandler:(void (^)(CMSampleBufferRef _Nullable imageDataSampleBuffer, NSError * _Nullable error))handler; 复制代码
完美解决:AVCapturePhotoCaptureDelegate
- (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhotoSampleBuffer:(CMSampleBufferRef)photoSampleBuffer previewPhotoSampleBuffer:(CMSampleBufferRef)previewPhotoSampleBuffer resolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings bracketSettings:(AVCaptureBracketedStillImageSettings *)bracketSettings error:(NSError *)error; - (void)captureOutput:(AVCapturePhotoOutput *)output willCapturePhotoForResolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings{ /// 释放声音 AudioServicesDisposeSystemSoundID(1108); } 复制代码
willCapturePhotoForResolvedSettings 时释放声音
AudioServicesDisposeSystemSoundID(1108); 复制代码
这样就可以了
我们来看看这个API
AudioServicesDisposeSystemSoundID(SystemSoundID inSystemSoundID) 复制代码
/*! @function AudioServicesDisposeSystemSoundID @abstract Allows the System Sound server to dispose any resources needed for the provided SystemSoundID. @discussion Allows the application to tell the System Sound server that the resources for the associated audio file are no longer required. @param inSystemSoundID A SystemSoundID that the application no longer needs to use. */ extern OSStatus AudioServicesDisposeSystemSoundID(SystemSoundID inSystemSoundID) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) 复制代码
A SystemSoundID that the application no longer needs to use.
应用程序不再需要使用的SystemSoundID。
其他:
1108 是非公开的音频ID,有可能被拒,但是有些竞品APP已经使用了这个,应该可以顺利上线。
这篇关于?? iOS如何拍照静音-效果上可以完美解决的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-10-05Swift语法学习--基于协议进行网络请求
- 2022-08-17Apple开发_Swift语言地标注释
- 2022-07-24Swift 初见
- 2022-05-22SwiftUI App 支持多语种 All In One
- 2022-05-10SwiftUI 组件参数简写 All In One
- 2022-04-14SwiftUI 学习笔记
- 2022-02-23Swift 文件夹和文件操作
- 2022-02-17Swift中使用KVO
- 2022-02-08Swift 汇编 String array
- 2022-01-30SwiftUI3.0页面反向传值