在AVCaptureDevice上切换Flash需要停止和启动AVCaptureSEssion [英] Toggling Flash on AVCaptureDevice requires Stopping and Starting AVCaptureSEssion
问题描述
在iOS 7中,为 AVCaptureDevice
使用时更改闪光灯状态:
In iOS 7 when changing the flash state for AVCaptureDevice
using:
if ([self.avCaptureDevice isFlashModeSupported:self.avCaptureFlashMode])
{
NSError *error = nil;
[self.avCaptureDevice lockForConfiguration:&error];
if (!error) [self.avCaptureDevice setFlashMode:self.avCaptureFlashMode];
[self.avCaptureDevice unlockForConfiguration];
}
设备不会使用闪存,除非 AVCaptureSessions
停止并以以下方式启动:
The device won't use the flash unless the AVCaptureSessions
is stopped and started with:
[self.avCaptureSession stopRunning];
[self.avCaptureSession startRunning];
这会使相机短暂闪烁为黑色。
This causes the camera to flash to black briefly. Is it possible to toggle the flash without stopping/starting the session?
推荐答案
我在iOS7中有一个类似的Flash相关的问题,其中仍然如果会话具有多个输出(静态和视频数据)并使用闪存,捕获将失败。在 https://devforums.apple.com/message/894764 中找到了解决方法(删除第二个在调用 captureStillImageAsynchronouslyFromConnection:completion
之前输出)。显然,这也会暂停视频,但它可能更适合,如果你有一个快门动画反正。
I had a similar flash related problem in iOS7 where still capture would fail if the session had multiple outputs (still and videodata) and the flash was used. Found a workaround in https://devforums.apple.com/message/894764 (removing the second output before calling captureStillImageAsynchronouslyFromConnection:completion
). Obviously this will also pause the video, but it may be more suitable if you have a shutter animation anyway.
这篇关于在AVCaptureDevice上切换Flash需要停止和启动AVCaptureSEssion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!