【发布时间】:2014-01-26 09:21:32
【问题描述】:
如何使AVCaptureSession 只扫描AVCaptureMetadataOutput ONCE。我一直在扫描一个条形码超过 30 次时遇到问题,将扫描声音延迟大约 2-3 秒,然后它会发出疯狂的哔哔声(字面意思)并显示 ~30 UIAlertViews!!
下面的代码是我尝试只扫描一次...
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
CGRect highlightViewRect = CGRectZero;
AVMetadataMachineReadableCodeObject *barCodeObject;
NSString *detectionString = nil;
NSArray *barCodeTypes = @[AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code];
for (AVMetadataObject *metadata in metadataObjects) {
for (NSString *type in barCodeTypes) {
if ([metadata.type isEqualToString:type])
{
barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
highlightViewRect = barCodeObject.bounds;
detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
break;
}
}
if (detectionString != nil)
{
[_session removeOutput:_output];
[_session stopRunning];
_session = nil;
_output = nil;
[_prevLayer removeFromSuperlayer];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/barcodeBeep.wav", [[NSBundle mainBundle] resourcePath]]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer play];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
任何帮助表示赞赏。
【问题讨论】:
标签: ios7 avcapturesession