The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
can't turn on lumia 1520 wp 8.1 flashlight use VideoDeviceController.TorchControl RRS feed

  • Question

  • my device is lumia 1520, updated to wp8.1

    os version:8.10.12397.895

    firmware version:02061.00066.14332.41004

    hardware version:6.3.0.0

    i use sample code from nokia developer website: http://developer.nokia.com/community/wiki/Using_the_camera_light_in_Windows_Phone_7,_8_and_8.1

            private async void Button_Click_test(object sender, RoutedEventArgs e)
            {
                var mc = new MediaCapture();
                await mc.InitializeAsync();
                var videodev = mc.VideoDeviceController;
                var tcontrol = videodev.TorchControl;
                tcontrol.Enabled = true;
            }

    when i press that button ,nothing happens,no light from led,no errors. breakpoint shows that tcontrol.Enabled value set true succefuly.

    lumia 1520 is set to develop mode, i use visual studio 2013.3 directly start debug from IDE

    the sample code need set tc.PowerPercent = 100; but on my device ,this is not supported.

    i also tried turn on video preview , and some more code :

                var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
                DeviceInformation rearCamera = null;
                //get rear camera
                foreach (DeviceInformation d in videoDevices)
                {
                    if (d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back)
                    {
                        rearCamera = d;
                        break;
                    }
                }
                if (rearCamera == null)
                {
                    //todo: show error,no rear camera
                    return -1;
                }
                //init device with rear camera id and check torch support
                MediaCaptureInitializationSettings cameraSettings = new MediaCaptureInitializationSettings();
                cameraSettings.VideoDeviceId = rearCamera.Id;
                mc = new MediaCapture();
                await mc.InitializeAsync(cameraSettings);
                if (mc.VideoDeviceController.TorchControl.Supported == false)
                {
                    //todo: error ,no support torchcontrol
                    return -1;
                }
                //start preview
                captureElement.Source = mc;
                await mc.StartPreviewAsync();
                //turn on video torch
                mc.VideoDeviceController.TorchControl.Enabled = true;

    this code is also no effect: no error ,no light

    Tuesday, September 30, 2014 8:00 AM

Answers

  • Hi,

    I think I've got the solution. And I've got why it will work this way from our product team. To make it work, we need to start video capture in order for 1520. Lumia 920 works because the camera driver which just happens to allow the flash hardware to turn on. To make all devices which has torchcontrol supported, we need to do something like the following:

                if (mc.VideoDeviceController.TorchControl.Supported)
                {
                    // But wait, for this to work with Blue camera drivers, we have to Start a recording session
                    // Create video encoding profile as MP4 
                    var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
    
                    // Start Video Recording
                    var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
                    await mc.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
    
                    // Turn on Torch                 
                    mc.VideoDeviceController.TorchControl.Enabled = true;
    
                }


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 22, 2014 3:21 AM

All replies

  • Hi,

    Thanks for posting on MSDN forum.

    I created a sample to reproduce this issue, but with these code snippets, I cannot reproduce this issue.

    Note:

    1. Not all flash modes are supported on all devices; it is important to call the IsFlashModeSupported(FlashMode) method to confirm that a mode is available before using it. Since I didn’t have Lumia 1520 on my side, I cannot test this issue. You can test it first.

    2. Don’t forget to add capabilities (ID_CAP_ISV_CAMERA) to your project.

    http://msdn.microsoft.com/en-us/library/windows/apps/hh202949(v=vs.105).aspx

    If this cannot help you to solve this issue, please share a sample for us.

    Best Regards,

    Jimmy Yang


    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.

    Wednesday, October 1, 2014 5:54 AM
  • sorry for the late response,

    1.
    i viewed 
    IsFlashModeSupported(FlashMode) ,it need  Microsoft.Devices namespace, my project use windows phone 8.1 templete, there is no Microsoft.Devices namespace i can referer. i try to create an empty project use windows phone silverlight 8.1 templete, it can use the  Microsoft.Devices namespace, but i cant use silverlight in this case.

    2.
    confirm : my project already added microphone and camera capabilities. camera preview from my app works fine, just flash torch can't work.

     i uploaded full project files to skydrive:

    https://onedrive.live.com/redir?resid=1FCD40CD64EB2C71!3116&authkey=!AH1IYgf0WYCO2Yo&ithint=file%2czip

    Wednesday, October 8, 2014 3:28 AM
  • Hi,

    Thanks for your sample. I downloaded it and tested on my side. I initialized the device and the click Flash On button. It works fine on my Lumia 920. But I will try to find a Lumia 1520 device to test this issue.

    In addition, I would suggest you download a flashlight app from Store, if other app works on your device, it will help to narrow down this issue is related to hardware or not.

    I reviewed the code. As we known, if the firmware version doesn’t meet the target, the TorchControl will not supported in Windows Phone runtime app. From your code snippet in Initial Device,

    	if (mc.VideoDeviceController.TorchControl.Supported == false)
    	{
    		TextBlock1.Text += "found one rear camera but do not support torch control\r\n";
    		return 0;
    	}

    It will help you to check this scenario. If this is the case, please update the firmware for your device.

    In addition, If this is a Silverlight flashlight app. It would be supported in this case. For code about Silverlight flashlight, you can follow the tutorial which you provided.

    If you have any future question regarding this, please feel free to let me know.

    Best Regards,

    Jimmy Yang


    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.

    • Marked as answer by Yang,Chenfei Monday, October 13, 2014 5:22 AM
    • Unmarked as answer by Yang,Chenfei Monday, October 13, 2014 5:38 AM
    Wednesday, October 8, 2014 6:56 AM
  • sorry for the late reply again..

    1.
    on my device, the mc.VideoDeviceController.TorchControl.Supported is true. 
    also checked firmware update, there's no new updates.

    2.there is an factory installed app on my device called "Nokia Camera". i start that app, switch to video recording mode, there is a flashlight icon on the screen, the LED light can turn on when i click that flashlight icon.

    Monday, October 13, 2014 5:33 AM
  • Hi,

    Could you please install one of the flashlight app listed on the link below,

    http://www.windowsphone.com/en-us/search?q=Flashlight

    And share the test result with me. In addition, as I mentioned in my last reply. Could you please create a Windows Phone Silverlight flashlight app for this issue? And give us the test result.

    In addition, I didn’t recommend you test this issue via Nokia Camera. Since it’s build by OEM. And OEM has more available APIs than individual developer.

    Best Regards,

    Jimmy Yang


    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, October 13, 2014 5:44 AM
  • hi,

    i installed the first app from your url's search result, the name is "FLASHLIGHT", author: Tony Sakariy, version 4.0.0.0, last update: 2014/9/15
    it works fine on my device.

    i will try to build a silverlight app to test the flashlight. i assume it will work, because the advance camera sample code from https://code.msdn.microsoft.com/Windows-Phone-81-samples-08631ca7 works fine on my device.(the different is that advance camera sample use flash mode, not the video torch)

    Tuesday, October 14, 2014 6:22 AM
  • here's the silverlight version:
    https://onedrive.live.com/redir?resid=1FCD40CD64EB2C71!3261&authkey=!AEGU8OOvoFGwVeo&ithint=file%2czip

    still no luck...

    base on above experience, i see the following result:
    torch code works on Lumia 920
    flash sample camera app works on Lumia 1520 (i can't find a fully compileable sample torch app)
    torch app from store works on Lumia 1520

    i think maybe i missed some small codes, maybe just one line to make it sucess, currently no clue.

    Tuesday, October 14, 2014 9:06 AM
  • Hi,

    I just looked into this. I tested the torchcontrol.enabled on my 1520 with latest update.

    The result is:

    1. Video preview works.

    2. Torchcontrol doesn't. But I got the supported property is true.

    I am trying to confirm this issue with product team. Will update here.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 14, 2014 1:17 PM
  • Hi,

    I think I've got the solution. And I've got why it will work this way from our product team. To make it work, we need to start video capture in order for 1520. Lumia 920 works because the camera driver which just happens to allow the flash hardware to turn on. To make all devices which has torchcontrol supported, we need to do something like the following:

                if (mc.VideoDeviceController.TorchControl.Supported)
                {
                    // But wait, for this to work with Blue camera drivers, we have to Start a recording session
                    // Create video encoding profile as MP4 
                    var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
    
                    // Start Video Recording
                    var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
                    await mc.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
    
                    // Turn on Torch                 
                    mc.VideoDeviceController.TorchControl.Enabled = true;
    
                }


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 22, 2014 3:21 AM
  • yeah, it's workd!  thank you!

    but why torchcontrol can't turn on in videopreview mode?  i have tried start video preview first but never think about it need to start a real recording.

    Sunday, October 26, 2014 1:34 AM
  • I remember it working like that in the early days of WP7.5 as well and I think it's a regression from my point of view. Great to at least have a workaround. Perhaps we can capture to a sink that simply discards the data so we don't fill up storage (even if we clean it up later on) just to turn on the Camera Torch.
    Sunday, October 26, 2014 1:14 PM
  • Hi,

    I think I've got the solution. And I've got why it will work this way from our product team. To make it work, we need to start video capture in order for 1520. Lumia 920 works because the camera driver which just happens to allow the flash hardware to turn on. To make all devices which has torchcontrol supported, we need to do something like the following:

                if (mc.VideoDeviceController.TorchControl.Supported)
                {
                    // But wait, for this to work with Blue camera drivers, we have to Start a recording session
                    // Create video encoding profile as MP4 
                    var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
    
                    // Start Video Recording
                    var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
                    await mc.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
    
                    // Turn on Torch                 
                    mc.VideoDeviceController.TorchControl.Enabled = true;
    
                }


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Hi,

    I have the same problem with nggg and I tried your help but it not work on my lumia 1520. I also install and test with flashlight app in the store and it work fine. So can you tell me does it work now? Here is my code:

    if (captureManager.VideoDeviceController.TorchControl.Supported)
            {
                var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
                StorageFolder folder = KnownFolders.VideosLibrary;
                StorageFile videoStorageFile;               
                videoStorageFile = await folder.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
                Capture.Source = captureManager;
                await captureManager.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
                captureManager.VideoDeviceController.TorchControl.Enabled = true;
                int i;
                for (i = 0; i < 3; i++)
                {
                    await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));
                }
                captureManager.VideoDeviceController.TorchControl.Enabled = false;
                captureManager.Dispose();
            }

    Thank in advance!

    Rain

    Thursday, July 30, 2015 3:39 AM
  • Depending on the devices camera driver, you may either need to turn on video recording or start preview before you set the TorchControl.Enabled property. To ensure this works with the widest range of devices, you should do both. This should be done with a async Task method to ensure the call completes before you attempt to toggle the torch. If you are using async void, there's no guarantee the call will complete before you attempt to toggle the torch. For preview you can create a CaptureElement in code and assign the source. Start preview code is just a few lines, something along the lines of:

    var captureElement = new CaptureElement();

    captureElement.Source = mediaCapture;

    await mediaCapture.StartPreviewAsync();


    Tom A | Microsoft | Windows Camera Team


    Friday, August 21, 2015 7:14 PM