如何在UWP C#中创建Flashlight应用

编程入门 行业动态 更新时间:2024-10-15 08:27:38
本文介绍了如何在UWP C#中创建Flashlight应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有Lumia 830,并且尝试使用UWP C#创建手电筒应用程序。我的设备手电筒效果很好,但我不知道为什么无法创建自己的应用程序,请打开/关闭手机的Torch。 我使用Lamp类:

I have Lumia 830 and i've tried to create flashlight app in UWP C#. my device Flashlight works great but i don't know why i can't create my own app turn on / off Torch of my phone. I use Lamp class :

var lamp = await Lamp.GetDefaultAsync(); if (lamp == null) { ShowErrorMessage("No Lamp device found"); return; } lamp.IsEnabled = true;

当在手机上运行此代码时, lamp为空,并且找不到我的FlashLED。我从 MSDN.Microsoft ,然后说

when run this code on my phone "lamp" is null and it couldn't find my FlashLED. I've got this code from MSDN.Microsoft and thay said

如果返回的对象为null,则设备不支持Lamp API。即使设备上实际存在灯泡,某些设备也可能不支持Lamp API。

If the returned object is null, the Lamp API is unsupported on the device. Some devices may not support the Lamp API even if there is a lamp physically present on the device.

此类我无法在Lumia 830上工作,我不知道为什么吗? :(

This class doesn't work on my Lumia 830 i don't kno why? :(

我也使用此代码:

var mediaDev = new MediaCapture(); await mediaDev.InitializeAsync(); var videoDev = mediaDev.VideoDeviceController; var tc = videoDev.TorchControl; if (tc.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 mediaDev.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile); // Turn on Torch mediaDev.VideoDeviceController.TorchControl.Enabled = true; }

此代码有效,并且我的FlashLED打开,但它记录了vid eo,并占用用户的SD卡内存。 ,如果您知道打开/关闭手电筒或FlashLED的最佳方法,请帮助我。 预先感谢侯赛因·哈比比(Hussein Habibi Juybari)

this code works and my FlashLED turn on but it record video and it take's user SD Card memory. please help me if you know there is best way to turn on/off Torch or FlashLED. thanks in advance Hussein Habibi Juybari

推荐答案

Lamp API仅适用于Windows 10设备,并且您只能在支持API的设备上使用它。当前支持的设备是950 / 950XL,650和550。较旧的设备将不会更新为支持此API。当您发现灯泡设备在较旧的设备上不可用时,您应该回到Windows 8.1开启闪光灯的方法。

The Lamp API is designed for Windows 10 devices only and you can only use it on devices which support the API. Currently supported devices are 950/950XL, 650, and 550. Older devices will not be updated to support this API. You should fall back to the Windows 8.1 method of turning on flash when you detect that the lamp device is not available on older devices.

发件人: wpdev.uservoice/forums/110705/suggestions/15846967

更多推荐

如何在UWP C#中创建Flashlight应用

本文发布于:2023-11-04 18:16:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   UWP   Flashlight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!