GPUImage2 icon indicating copy to clipboard operation
GPUImage2 copied to clipboard

How to integrate Flash/Torch?

Open aaasifrz9 opened this issue 6 years ago • 3 comments

Hi @BradLarson,

I tried to identify AVCaptureTorchMode for integration of Flash/Torch but not able to get anything. 1- How can I integrate it? 2- How can I change mode ON/OFF?

Please help. Thanks in advance.

aaasifrz9 avatar Jan 22 '18 11:01 aaasifrz9

Actually, we are not able to access inputCamera:AVCaptureDevice of class Camera because this variable is not public. Please do the needful. Either make it public or provide any method to enable torch. Thanks in advance.

aaasifrz9 avatar Jan 30 '18 12:01 aaasifrz9

extension AVCaptureDevice {
    func setTorchMode(mode: AVCaptureTorchMode) {
        do {
            try self.lockForConfiguration()
            
            if(self.hasTorch && self.isTorchModeSupported(mode)) {
                self.torchMode = mode
            }
            
            self.unlockForConfiguration()
        } catch {
            print("Could not set flash mode: \(error)")
        }
    }
}

Then make sure the inputCamera var is public on the Camera class and you can do the following:

self.camera!.inputCamera.setTorchMode(mode: .auto)

joshbernfeld avatar Mar 01 '18 00:03 joshbernfeld

Thanks @joshbernfeld

aaasifrz9 avatar Mar 05 '18 05:03 aaasifrz9