Switch flashlight in Windows Phone 8.1

Can anyone tell how to switch flashlight in Windows Phone 8.1 using C #? It seems that there are many API changes in Windows Phone 8.1, and most of the APIs in WP 8.0 are not supported. The answers are highly appreciated.

+4
source share
5 answers

I can use TorchControl on my Lumia 820, like this - first you have to indicate which camera you will use - default is the front (I think you can find some problems), and we want the reverse one that has there is a flash. Code example:

// edit - I forgot to show GetCameraID:
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
    DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
        .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);

    if (deviceID != null) return deviceID;
    else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desiredCamera));
}

// init camera
async private void InitCameraBtn_Click(object sender, RoutedEventArgs e)
{
    var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
    captureManager = new MediaCapture();

    await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
        {
            StreamingCaptureMode = StreamingCaptureMode.Video,
            PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
            AudioDeviceId = string.Empty,
            VideoDeviceId = cameraID.Id
        });
}

// then to turn on/off camera
var torch = captureManager.VideoDeviceController.TorchControl;
if (torch.Supported) torch.Enabled = true;

// turn off
if (torch.Supported) torch.Enabled = false;

Please note that after you are done with it, you can call captureManager.Dispose().


, / .

+6

Windows Phone 8.1 - API . API Windows 8.1, Windows Phone 8.1 Windows Phone Silverlight 8.1.

var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync();
var videoDev = mediaDev.VideoDeviceController;
var tc = videoDev.TorchControl;
if (tc.Supported)
   {
   if (tc.PowerSupported)
      tc.PowerPercent = 100;
   tc.Enabled = true;
   }

: . TorchControl.Supported false WP8.1. , 8.1 . : Lumia 620, 822, 1020: , Lumia 1520: .

+4

Nokia Lumia 1520 FlashControl, TorchControl.

    //to switch OFF flash light
    mediacapture.VideoDeviceController.FlashControl.Enabled = false;
    //to switch ON flash light
    mediacapture.VideoDeviceController.FlashControl.Enabled = true;
+2

Doesn't work on my Lumia 1520. You need to start video recording to get the flashlight working:

        var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);

        var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
        await captureManager.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
+1
source

In my Lumia 1520. I need to start the video recording and start the preview in order to get the flashlight working:

await captureManager.StartPreviewAsync();
+1
source

All Articles