在Windows Phone的8.1切换手电筒 [英] Toggle flashlight in Windows Phone 8.1

查看:307
本文介绍了在Windows Phone的8.1切换手电筒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以说,如何使用C#切换手电筒的Windows Phone 8.1吗?好像有很多的的Windows Phone 8.1 API的变化,最WP 8.0的API的不支持。答案是高度赞赏。

Can anyone say how to toggle flashlight in Windows Phone 8.1 using C#? It seems like there are lots of API changes in Windows Phone 8.1 and most of the API's in WP 8.0 are not supported. Answers are highly appreciated.

推荐答案

我能使用的 TorchControl 我的Lumia 820这样的 - 首先你要指定相机你会使用 - 默认为前(我认为这就是为什么你会发现一些问题),我们要背一 - 一个与闪光灯。示例代码:

I'm able to use TorchControl on my Lumia 820 like this - first you have to specify which camera you will use - the default is front (I think that's why you may find some problems) and we want the back one - the one with flash light. Sample code:

// 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;

请注意,这是一个好主意,叫 captureManager.Dispose()你用它完成了。

Note that it's a good idea to call captureManager.Dispose() after you finish with it.

还请注意,在某些手机上打开手电筒/手电筒您首先需要启动预览。

Note also that on some phones to turn on torch/flashlight you will need to start preview first.

这篇关于在Windows Phone的8.1切换手电筒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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