Windows Phone 8(HTC 8X)手电筒无法开启(不使用相机)

时间:2013-02-25 21:55:41

标签: c#-4.0 reflection windows-phone-8 flashlight

作为一名新手程序员,我会问一个愚蠢的问题。我想打开Windows Phone 8的手电筒而不会闪烁(像其他手电筒应用程序一样)。现在我尝试使用
的示例 Reflection failure when attempting to access Microsoft.Phone.Media.Extended

但它不起作用。我创建了一个名为“flash”的按钮并粘贴代码。它编译得很好,但我的设备HTC 8X甚至没有打开手电筒一秒钟。我该做什么 ?

图书馆&我用过的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Flashlight_V_0._1.Resources;
using Microsoft.Phone.Media;
using Windows.Phone.Media.Capture; 
using Microsoft.Xna.Framework.Media;
using System.IO;                     

namespace Flashlight_V_0._1
{

    public partial class MainPage : PhoneApplicationPage
    {

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var sensorLocation = CameraSensorLocation.Back;

            try
            {
                // get the AudioViceoCaptureDevice
                var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
                    AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());

                // turn flashlight on
                var supportedCameraModes = AudioVideoCaptureDevice
                    .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
                if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
                {
                    avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);

                    // set flash power to maxinum
                    avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                        AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
                }
                else
                {
                    //ShowWhiteScreenInsteadOfCameraTorch();
                }

            }
            catch (Exception ex)
            {
                // Flashlight isn't supported on this device, instead show a White Screen as the flash light
                //ShowWhiteScreenInsteadOfCameraTorch();
            }

        }

    }
}

我也试过这个:

        try
        {

            var _device = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());

            _device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
        }
        catch (Exception ex)
        {
            //
        }

我做错了什么?

1 个答案:

答案 0 :(得分:1)

很抱歉迟到的回复,得到它但不能发布。对此。 WP7 / WP7.5默认访问所有传感器。但在WP8中,您必须手动启用传感器功能。

  1. 转到解决方案资源管理器。
  2. 选择项目。
  3. 选择属性 - > WMAppManifest.xml
  4. 双击'WMAppManifest.xml'
  5. 选择“功能”
  6. 启用适当的应用功能
  7. 要解决我的问题,我必须启用两项功能。

    1. ID_CAP_ISV_CAMERA
    2. ID_CAP_MICROPHONE
    3. 谢谢你