User Media Plug in needs to support camera FLASH, or TORCH

0 favourites
  • 2 posts
From the Asset Store
Platform Game Template. Source File, music and art pack for The Torch Bearer Platform Game
  • The User Media Plug in needs to support Camera FLASHLIGHT, or TORCH functions.

    There are many situations where poor lighting requires a camera FLASH to take a

    decent picture.

    TORCH ON

    TORCH OFF

    TORCH FLASH

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The following code works to turn ON the camera FLASHLIGHT, if this helps.

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

    	<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>
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)