最近碰到需求,要拍照时候没有声音,用AVCaptureStillImageOutput拍照会有快门声,查了网上的使用了反向声音的方式,但是因为要连拍会导致有些时候声音不同步,还是会有漏网的快门声,最后研究了一下使用了AVCaptureVideoDataOutput来对图像进行输出,没有了快门声音,代码如下:
//初始化
- (void)initAVCaptureSession{
AVCaptureSession *session = [[AVCaptureSession alloc] init];
NSError *error;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//更改这个设置的时候必须先锁定设备,修改完后再解锁,否则崩溃
[device lockForConfiguration:nil];
//设置闪光灯为自动
if ([device isFlashModeSupported:AVCaptureFlashModeOff]) {
[device setFlashMode:AVCaptureFlashModeOff];
};
[device unlockForConfiguration];
self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error];
if (error) {
NSLog(@"%@",error);
}
// Create a VideoDataOutput and add it to the session
self.imageOutput = [[AVCaptureVideoDataOutput alloc] init];
[self.session addOutput:self.imageOutput];
// Configure your output.
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[self.imageOutput setSampleBufferDelegate:s