时间: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已经使用了这个,应该可以顺利上线。
加V备注:掘金;入群一起学习🐻