在AVCaptureDevice上切换Flash需要停止和启动AVCaptureSEssion [英] Toggling Flash on AVCaptureDevice requires Stopping and Starting AVCaptureSEssion

查看:290
本文介绍了在AVCaptureDevice上切换Flash需要停止和启动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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆