我正在使用苹果的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];
}
}
});
}它在代码中遍历每一行,不记录由此产生的任何错误,但仍然没有任何运气。
发布于 2014-11-25 06:27:50
- (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];
}
}在我的情况下,火炬/闪光灯一开始就关闭了。
https://stackoverflow.com/questions/27119603
复制相似问题