简体   繁体   中英

WindowsPhone 8.1 FlashLight

I have Nokia 730 and I want to make FlashLight work on it. But next code crash:

     MediaCapture mc = new MediaCapture();
        await mc.InitializeAsync();

            if (mc.VideoDeviceController.TorchControl.Supported == true)
            {
                mc.VideoDeviceController.TorchControl.Enabled = true;
                mc.VideoDeviceController.TorchControl.PowerPercent = 100; // here is crash
            }

Any ideas? For some reasons solutions with older platforms (wp 7, wp8) doesn't works at all.

Fixed it by next code:

        private async void Button_Click(object sender, RoutedEventArgs e)
    {
        // Initialize Media Capture and Settings Objects, mediaCapture declared global outside this method 
        var mediaCapture = new MediaCapture();

        // Grab all available VideoCapture Devices and find rear device (usually has flash)
        await mediaCapture.InitializeAsync();

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

        var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
        await mediaCapture.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);

        await Task.Delay(TimeSpan.FromMilliseconds(500));
        mediaCapture.VideoDeviceController.TorchControl.Enabled = true;
    }

But for some reason I should wait 500 milliseconds before enable TorchControl. Can someone explain why?

According to this post it could help to try the following:

//to switch OFF flash light
mc.VideoDeviceController.FlashControl.Enabled = false;
//to switch ON flash light
mc.VideoDeviceController.FlashControl.Enabled = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM