← All extensions

Native extension

KlugTorch

com.klug.torch.Torch

Detects whether a device has a camera light, and switches it on and off while the camera is streaming, without interrupting the stream.

iOSAndroid In production

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

iOS arm64
Android arm64 · armv7

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:

app.xml
<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

Light.as
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.
isSupportedTrue only if the device has a camera light (iOS and Android).
on()Turns the camera light on.
off()Turns the camera light off.
modeTrue while the light is on.
Events: "on", "off", "error"Dispatched when the light changes or cannot be switched.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 17 or later
AndroidAndroid 6.0 (API 23) or later
PermissionsCamera (already granted for the stream)
HardwareA camera light next to the back camera