How do I control Android camera flash?

0 favourites
  • 14 posts
From the Asset Store
A collection of 10 amazing sprite sheet animations for your incredible games
  • Is it possible to control a Android phones flash from a construct game? I know you can use the actual cameras but I can not find anything about using the flash.

  • Not a single answer?

  • Not a single answer?

    man i feel your pain. now 2020 and i'm looking for answer to this exact question for the 3rd time and still nothing at all yet from anyone.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • simple answer. No it is not possible.

  • Hey all,

    Ok, I found this on stack overflow which includes code that I got working on my Android phone.

    stackoverflow.com/questions/37848494/is-it-possible-to-control-the-camera-light-on-a-phone-via-a-website/47153547

    PLEASE let me know if anyone can use this code within Construct

  • Try this link also

    jsfiddle.net/39puneug/4

  • use cordova flashlight plugin

    i use it for several apps using construct 2

  • WOW !!!

    Thank you MatrixReal..

    Will this run within a Chrome web browser?

    My application needs to run within a web browser and specifically NOT INSTALL

    as an APP on the phone devices, or tablets.

  • I found this code, that works on Android..

    ==============================================================================================

    	<html>
    		<body>
    //Test browser support
    const SUPPORTS_MEDIA_DEVICES = 'mediaDevices' in navigator;
    
    if (SUPPORTS_MEDIA_DEVICES) {
     //Get the environment camera (usually the second one)
     navigator.mediaDevices.enumerateDevices().then(devices => {
     
     const cameras = devices.filter((device) => device.kind === 'videoinput');
    
     if (cameras.length === 0) {
     throw 'No camera found on this device.';
     }
     const camera = cameras[cameras.length - 1];
    
     // Create stream and get video track
     navigator.mediaDevices.getUserMedia({
     video: {
     deviceId: camera.deviceId,
     facingMode: ['user', 'environment'],
     height: {ideal: 1080},
     width: {ideal: 1920}
     }
     }).then(stream => {
     const track = stream.getVideoTracks()[0];
    
     //Create image capture object and get camera capabilities
     const imageCapture = new ImageCapture(track)
     const photoCapabilities = imageCapture.getPhotoCapabilities().then(() => {
    
     //todo: check if camera has a torch
    
     //let there be light!
     const btn = document.querySelector('.switch');
     btn.addEventListener('click', function(){
     track.applyConstraints({
     advanced: [{torch: true}]
     });
     });
     });
     });
     });
     
     //The light will be on as long the track exists
     
     
    }
    <button class="switch">On / Off</button>
    		</body>
    	</html>
    
  • In the example JAVA script I posted here, there is a BUTTON created that turns ON the TORCH Flashlight..

    After the JAVA script, there is HTML creating a BUTTON that shows up and executes the JAVA script command

    to turn ON the TORCH Flashlight..

    I can use the BROWSER Plugin to execute the java script code..

    QUESTION: How do I get a Construct BUTTON to execute the JAVA scripted button command?

  • Hey MatrixReal,

    Do you have any information on that "cordova flashlight plugin" you mentioned?

    I am running into major roadblocks trying to find it, or get anything else working.

    At this point, I am getting desperate..

  • think this is the link being referred to

    construct.net/en/make-games/addons

  • wowwowwwowwahhwow!!

    i think i may have cracked it!, i have been going insane trying to figure this out, and finally i have managed it.

    Previously i would click File Selectand get the message "Not enough memory to perform this operation", whenever i tried to select the camera (device's camera), Not "User Media" plugin.

    so i tried the following and it worked.

    1. open your device's camera
    1. access settings
    1. change resolution to a smaller one
    1. now open a preview of your app, and click "File Selector
    1. choose your device camera and it should then work, including flash
  • Thank you for the reply...

    I paid a guy to program an ADDON for the "User Media" Plugin

    that creates a FLASH ON - OFF function.

    I can share it with you if you need it?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)