I want to turn on torch mode AVCaptureTorchModeOn in my app while doing video recording.
I m using below code.
-(void)set_TorchMode:(BOOL)turnOn
{
AVCaptureDevice *theDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([theDevice hasTorch]) {
[theDevice lockForConfiguration: nil];
AVCaptureTorchMode currentMode = [theDevice torchMode];
BOOL isAlreadyTurnedOn = (AVCaptureTorchModeOn == currentMode);
if (isAlreadyTurnedOn != turnOn) {
[theDevice setTorchMode: turnOn? AVCaptureTorchModeOn: AVCaptureTorchModeOff];
}
[theDevice unlockForConfiguration];
}
}
I m calling this method while start recording to turn ON and while stop recording to turn it OFF.
Its working fine for me first time when i record, but while start recording second time, its turn on but immediately turns OFF.Its not keeping ON while recording is running.
Thanks for any help.
An object that configures capture behavior and coordinates the flow of data from input devices to capture outputs.
AVFoundation is Apple's advanced framework for working with time-based media, such as audio and video. This course covers the essentials to using the AVFoundation framework to create audio based apps.
Following code is implemented for the turn on and off back light .
May this helping to you,
- (void) setTorchOn:(BOOL)isOn
{
AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil]; //you must lock before setting torch mode
[device setTorchMode:isOn ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];
[device unlockForConfiguration];
}
- (IBAction)changedState:(id)sender {
UISwitch *switchValue = (UISwitch*)sender;
[self setTorchOn:[switchValue isOn]];
}
please test this code into the devices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With