0

我正在使用 Apple 的AVCam 源代码创建自定义相机,我正在尝试打开/关闭闪光灯,但它不起作用。这是我的代码,不知道出了什么问题。我是 AVCam 的新手。

- (void) toggleFlash:(id)sender {
    dispatch_async([self sessionQueue], ^{
        AVCaptureDevice *currentVideoDevice = [[self videoDeviceInput] device];
        AVCaptureDevicePosition currentPosition = [currentVideoDevice position];
        if(currentPosition == AVCaptureDevicePositionUnspecified || currentPosition == AVCaptureDevicePositionBack) {
            if([currentVideoDevice hasFlash]) {
                [currentVideoDevice lockForConfiguration:nil];
                [currentVideoDevice setFlashMode:AVCaptureFlashModeOn];
                [currentVideoDevice unlockForConfiguration];
            }
        }
    });
}

它遍历代码中的每一行,并没有记录任何错误,但仍然没有运气。

4

1 回答 1

0
- (void) toggleFlash {
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([device hasTorch] && [device hasFlash]){
        [device lockForConfiguration:nil];
        [device setTorchMode:!device.torchActive];
        [device setFlashMode:!device.torchActive];
        [device unlockForConfiguration];
    }
}

PS 在我的情况下,手电筒/闪光灯最初是关闭的。

于 2014-11-25T06:27:50.557 回答