如何在UWP C#中创建Flashlight应用 [英] How can i create Flashlight app in uwp C#

查看:106
本文介绍了如何在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.com ,然后说

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.com 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.

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

这篇关于如何在UWP C#中创建Flashlight应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆