private async Task <bool> InitTorchControl() { var cameraId = await _systemService.GetCameraIdAsync(Panel.Back); _mediaCapture?.Dispose(); _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = cameraId.Id }); var videoDeviceController = _mediaCapture.VideoDeviceController; _torchControl = videoDeviceController.TorchControl; this.TorchSupported = _torchControl.Supported; if (this.TorchSupported && _torchControl.PowerSupported) { this.FlashPowerValue = SettingsHelper.GetValueOrDefault("flashPowerValue", 0.5); } RaisePropertyChanged(nameof(FlashPowerSupported)); return(true); }
private async void Torch_Click(object sender, RoutedEventArgs e) { CaptureElement captureUI = new CaptureElement(); try { MediaCapture mediaCapture = new MediaCapture(); var cam = await GetCam(); await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = cam.Id, AudioDeviceId = string.Empty, StreamingCaptureMode = StreamingCaptureMode.Video, PhotoCaptureSource = PhotoCaptureSource.VideoPreview }); captureUI.Source = mediaCapture; await mediaCapture.StartPreviewAsync(); torchControl = mediaCapture.VideoDeviceController.TorchControl; if (torchControl.Supported) { Debug.WriteLine("Вспышка поддерживается"); } else { Debug.WriteLine("Вспышка не поддерживается"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private async void Initialize() { try { var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid() + ".mp4", CreationCollisionOption.ReplaceExisting); await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga), file); var videoDev = mediaCapture.VideoDeviceController; videoDev.TorchControl.Enabled = true; _torchControl = videoDev.TorchControl; TorchSupported = _torchControl.Supported; TorchPowerSupported = _torchControl.PowerSupported; if (TorchPowerSupported) _torchControl.PowerPercent = PercentValue; if (TorchSupported) _torchControl.Enabled = IsOn; _isInitialized = true; _toggleTorchCommand.RaiseCanExecuteChanged(); } catch (Exception ex) { ErrorMessage = "Etwas unerwartetes ist passiert. Entschuldige!"; } }