Michael_22 0 Newbie Poster

I need to turn ON and OFF the built in camera LED FLASHER on a Windows 8 tablet.
This is bascially the same as a common FLASHLIGHT APP on a cell phone.

I need to make this work within a Delphi 2010 VCL application and all I can
find is code written in C++. I do not know how to implement the Windows system
function calls for the "AudioVideoCaptureDevice" method.

The code snippet below is from a fully functional FLASHLIGHT APP for Windows 8 devices.

HELP !!!! PLEASE !!!

var sensorLocation = CameraSensorLocation.Back;

try
{
    // get the AudioViceoCaptureDevice
    var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
        AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());

    // turn flashlight on
    var supportedCameraModes = AudioVideoCaptureDevice
        .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
    if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
    {
        avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);

        // set flash power to maxinum
        avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
            AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
    }
    else
    {
        ShowWhiteScreenInsteadOfCameraTorch();
    }

}
catch(Exception ex)
{
    // Flashlight isn't supported on this device, instead show a White Screen as the flash light
    ShowWhiteScreenInsteadOfCameraTorch();
}

Dani AI

Generated

The C# snippet posted by uses the Windows Phone camera API (the AudioVideoCaptureDevice / KnownCameraAudioVideoProperties approach). That API is the Windows Phone (Silverlight) camera model; on Windows Store / UWP devices the supported path is MediaCapture → VideoDeviceController → TorchControl (or the Flash/Torch controls on the VideoDeviceController). (syncfusion.com)

Delphi 2010 is a classic Win32/VCL compiler and predates native WinRT/UWP support, so it cannot directly call those WinRT camera APIs. Two practical choices exist: (A) implement the flashlight as a Store/UWP (or Phone) app in C# / C++ that uses MediaCapture/TorchControl (or AudioVideoCaptureDevice on older WP Silverlight), or (B) build a small helper component/program (written with Visual Studio) that toggles the torch and invoke that helper from the Delphi app (ShellExecute/CreateProcess or IPC). Note that any WinRT/UWP code must declare camera capabilities in its package manifest. (stackoverflow.com)

Recommended minimal workflow (safe, practical):

  • Create a tiny UWP/Store app or WinRT component in C# or C++ that initializes MediaCapture for the back camera, checks the Torch/Flash support, starts preview (many devices only emit torch light while preview/recording is running), and sets TorchControl.Enabled / PowerPercent. If the device lacks torch support, expose a fallback (white-screen). (learn.microsoft.com)
  • Expose a simple interface for Delphi to call: a command-line exe (args "on"/"off"), a local TCP/UDP endpoint, or a small COM/WinRT server if feasible.
  • From Delphi 2010 call that helper. Example launcher (Delphi) to run a helper exe:
uses
  Windows, SysUtils;

procedure RunTorchHelper(const Args: string);
var
  si: TStartupInfo;
  pi: TProcessInformation;
  CmdLine: string;
begin
  ZeroMemory(@si, SizeOf(si));
  si.cb := SizeOf(si);
  CmdLine := 'C:\Path\TorchHelper.exe ' + Args;
  if not CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, si, pi) then
    RaiseLastOSError
  else
  begin
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
  end;
end;

Troubleshooting notes: verify the device actually supports torch/torch power, keep the MediaCapture preview running before enabling the torch (some hardware requires it), and handle the case where torch is unsupported by showing a white screen. For phone-only samples that toggle VideoTorchMode see the existing C# examples; they illustrate storing the device instance and switching On/Off. (stackoverflow.com)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.