locked
[WP8.1][HTML]WinJS - Unable to switch on flashlight (using torchControl) on Lumia 930

    Question

  • Hello,

    I am unable to switch on flashlight using torchControl on my lumia 930, when compiled the code gives no error and the app opens perfectly on the device. I researched a lot but was unable to find a solution to the problem... please help out.

    Thanks in advance.

    ---

    Here's the code that switches the flashlight on:

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            // This function is called whenever a user navigates to this page. It
            // populates the page elements with the app's data.
            ready: function (element, options) {
                // TODO: Initialize the page here.
                var flashlight = new Flashlight();
                result.innerHTML = Flashlight.sendHTML();
                var mediaDev = new Windows.Media.Capture.MediaCapture();
                mediaDev.initializeAsync().then(function () {
                    VideoDeviceController.torchControl.Enabled = true;
    
                });
                ON.addEventListener("click", function () {
                    Flashlight.lightON();
                    result.innerHTML = Flashlight.sendHTML();
                });
                OFF.addEventListener("click", function () {
                    Flashlight.lightOFF();
                    result.innerHTML = Flashlight.sendHTML();
                });
    
            }
        });
    })();



    • Edited by Dcodern17 Friday, May 1, 2015 1:14 PM
    • Edited by Jamles HezModerator Monday, May 4, 2015 3:16 AM add title tag per https://social.msdn.microsoft.com/Forums/en-US/b479e984-ca39-4b34-a6b7-85194b54d8bd/guide-to-posting-subject-line-tags
    Friday, May 1, 2015 1:12 PM

All replies

  • Hi Dcodern17,

    As I mentioned before, there could be a known solution for your issue, https://social.msdn.microsoft.com/Forums/windowsapps/en-US/329c40e7-fa9a-4a27-8347-b4a80100842e/cant-turn-on-lumia-1520-wp-81-flashlight-use-videodevicecontrollertorchcontrol?forum=wpdevelop

    We have to start the recording and then enable the troch light.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 4, 2015 2:52 AM
    Moderator
  • I made some changes, but they don't seem to work...

    Please help.

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            // This function is called whenever a user navigates to this page. It
            // populates the page elements with the app's data.
            ready: function (element, options) {
                // TODO: Initialize the page here.
                var oMediaCapture;
                var profile;
                var captureInitSettings;
                var deviceList = new Array();
                var recordState = false;
                var storageFile;
                initialization();
    
    
                function errorHandler(e) {
                    document.getElementById("message").innerHTML = e.message + ", Error Code: " + e.code;
                }
    
    
    
                // Begin initialization.
                function initialization() {
                    document.getElementById("message").innerHTML = "Initialization started.";
                    enumerateCameras();   
                }
    
    
                // Identify available cameras.
                function enumerateCameras() {
                    var deviceInfo = Windows.Devices.Enumeration.DeviceInformation;
                    deviceInfo.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture).then(function (devices) {
                        // Add the devices to deviceList
                        if (devices.length > 0) {
               
                            for (var i = 0; i < devices.length; i++) {
                                deviceList.push(devices[i]);              
                            }
         
                            initCaptureSettings();
                            initMediaCapture();
                            document.getElementById("message").innerHTML = "Initialization complete.";
    
                        } else {
                            sdkSample.displayError("No camera device is found ");            
                        }
                    }, errorHandler);
                }
    
    
                // Initialize the MediaCaptureInitialzationSettings.
                function initCaptureSettings() {
                    captureInitSettings = null;
                    captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                    captureInitSettings.audioDeviceId = "";
                    captureInitSettings.videoDeviceId = "";
                    captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audioAndVideo;
                    captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
                    if (deviceList.length > 0)
                        captureInitSettings.videoDeviceId = deviceList[0].id;
                }
    
    
                // Create a profile.
                function createProfile() {
                    profile = Windows.Media.MediaProperties.MediaEncodingProfile.createMp4(
                        Windows.Media.MediaProperties.VideoEncodingQuality.hd720p);
                }
    
                // Create and initialze the MediaCapture object.
                function initMediaCapture() {
                    oMediaCapture = null;
                    oMediaCapture = new Windows.Media.Capture.MediaCapture();
                    oMediaCapture.initializeAsync(captureInitSettings).then (function (result) {
                        createProfile();
                    }, errorHandler);    
                }
    
    
                // Start the video capture.
                function startMediaCaptureSession() {
                    Windows.Storage.KnownFolders.videosLibrary.createFileAsync("cameraCapture.mp4", Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (newFile) {
                        storageFile = newFile;
                        oMediaCapture.startRecordToStorageFileAsync(profile, storageFile).then(function (result) {
                            var torchControl = VideoDeviceController.torchControl;
                            var enabled = torchControl.enabled;
                            torchControl.enabled = enabled;
                        }, errorHandler);
                    });
                }
    
                // Stop the video capture.
                //function stopMediaCaptureSession() {
                    //oMediaCapture.stopRecordAsync().then(function (result) {
            
                    //}, errorHandler);         
    
                //}
            }
        });
    })();
    
    Thanks in advance !

    Monday, May 4, 2015 1:51 PM
  • Hi Dcodern17,

    I cannot directly run the code you shared, seems missed some variable also functions.

    I would suggest you share me a repro sample for a better test. Share via OneDrive is suggested :)

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 8, 2015 3:32 AM
    Moderator