2016-01-23 27 views
0

我有诺基亚730,我想让FlashLight工作。但下一次代码崩溃:WindowsPhone 8.1 FlashLight

 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 
      } 

任何想法?由于某些原因,旧版平台(wp 7,wp8)的解决方案完全不起作用。

+0

什么意思是“代码崩溃”?有一些例外吗?如果是,哪个? –

+0

不支持PowerPercent – Ted

+0

[在Windows Phone 8.1中切换手电筒]可能的副本(http://stackoverflow.com/questions/24847510/toggle-flashlight-in-windows-phone-8-1) – fillobotto

回答

0

根据this post它可以帮助尝试以下操作:

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

不起作用.. ..也试过: _mediaDev.VideoDeviceController.FlashControl.Auto = false; _mediaDev.VideoDeviceController.FlashControl.AssistantLightEnabled = true; _mediaDev.VideoDeviceController.FlashControl.Enabled = true; – Ted

1

通过下面的代码修正它:

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

但由于某些原因,我应该等待500毫秒之前启用TorchControl。有人能解释为什么吗?