Overview
A camera app often needs light: a pet camera in a dark room, a scanner, a video call at night. KlugTorch switches the camera light (the LED next to the back camera) on and off while the camera keeps running.
KlugTorch first detects whether the device has a camera light at all. Many tablets and some phones have none, so an app can simply hide its light button there.
It works alongside a live camera stream. KlugTorch does not open a camera of its own, so it never competes with the stream for the camera.
Apps that stream with KlugMedia can also use its built-in torch control. KlugTorch is in daily use in the PetCam App, our proof of concept.
Features
- Detects whether the device has a camera light
- Turn the camera light on and off with one call
- Works while the camera is streaming, no interruption
- Reads the current state of the light
- Events for on, off and errors
- One API for iOS and Android
Supported platforms
On devices without a camera light, and on other platforms, isSupported returns false, so the same code can stay in every app.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.torch.Torch</extensionID>
</extensions>
The light sits next to the back camera, so the back camera should be the active one.
Quick example
import com.klug.torch.Torch; var torch:Torch = Torch.getInstance(); torch.addEventListener( "error", onTorchError ); if ( torch.isSupported ) // false if the device has no camera light { if ( torch.mode ) torch.off(); else torch.on(); }
API overview
| Torch.getInstance() | Returns the single instance. |
| isSupported | True only if the device has a camera light (iOS and Android). |
| on() | Turns the camera light on. |
| off() | Turns the camera light off. |
| mode | True while the light is on. |
| Events: "on", "off", "error" | Dispatched when the light changes or cannot be switched. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| iOS | iOS 17 or later |
| Android | Android 6.0 (API 23) or later |
| Permissions | Camera (already granted for the stream) |
| Hardware | A camera light next to the back camera |