private void ToggleFlash() { try { IReadOnlyList <object> supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); //ToDo Don't like this line. Simplify.... if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { if (!_flashOn) { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On); _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation, KnownCameraAudioVideoProperties .VideoTorchPower) .Max); _contentGrid.Background = new SolidColorBrush(Colors.White); _flashOn = true; } else { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); _contentGrid.Background = null; _flashOn = false; } } } catch (Exception ex) { _shakeStatusTextBlock.Text = "The flash cannot be controlled on this device."; } }
private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e) { MobileBarcodeScanner.Log("Initialized Camera"); if (_photoCamera == null) { return; } MobileBarcodeScanner.Log("Creating Luminance Source"); var width = Convert.ToInt32(_photoCamera.PreviewResolution.Width); var height = Convert.ToInt32(_photoCamera.PreviewResolution.Height); _luminance = new PhotoCameraLuminanceSource(width, height); var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_photoCamera.SensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { _photoCamera.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); } _initialized = true; MobileBarcodeScanner.Log("Luminance Source Created"); OnCameraInitialized(_initialized); }
/// <summary> /// Turn the lamp on /// </summary> public async void TurnOn() { // further information about accessing the camera light can be found here: // http://developer.nokia.com/community/wiki/Using_the_camera_light_in_Windows_Phone_7,_8_and_8.1 if (_avDevice == null) { _avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()); } // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(CameraSensorLocation.Back, 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(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchPower).Max); } else { Debug.WriteLine("Torch Mode not supported by this device"); } }
/// <summary> /// Turn the lamp off /// </summary> public async void TurnOff() { if (_avDevice == null) { _avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()); } // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { _avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); // set flash power to maxinum _avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchPower).Max); } else { Debug.WriteLine("Torch Mode not supported by this device"); } }
public void TurnOnFlashlight() { var sensorLocation = CameraSensorLocation.Back; try { //turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { if (App.AvDevice != null) { App.AvDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On); // set flash power to maxinum App.AvDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max); } } } catch (Exception) { } }
private void ToggleFlash() { IReadOnlyList <object> supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { if (!_flashOn) { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On); _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation, KnownCameraAudioVideoProperties .VideoTorchPower) .Max); _flashOn = true; } else { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); _flashOn = false; } } }
private async void InitializeCaptureDevice() { captureDevice = await GetCaptureDevice(); IReadOnlyList <object> supportedModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); flashSupported = supportedModes.ToList().Contains((UInt32)VideoTorchMode.On); }
/// <summary> /// Here's where the magic happens. /// </summary> private void ToggleFlash() { try { var vibrator = VibrateController.Default; var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { if (!_flashOn) { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On); _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max); if (_appSettings.EnableSoundSetting) { SoundEffects.PlaySound(new Uri(soundOn, UriKind.Relative)); } if (_appSettings.EnableVibrateSetting && vibrator != null) { vibrator.Start(new TimeSpan(0, 0, 0, 0, 20)); } TorchButton.Background = _torchOnImage; _flashOn = true; } else { _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); if (_appSettings.EnableSoundSetting) { SoundEffects.PlaySound(new Uri(soundOff, UriKind.Relative)); } if (_appSettings.EnableVibrateSetting && vibrator != null) { vibrator.Start(new TimeSpan(0, 0, 0, 0, 10)); } TorchButton.Background = _torchOffImage; _flashOn = false; } } } catch (Exception ex) { DebugText.Text = ex.Message; } // Update battery icon SetBatteryIcon(); }
public async Task InitAsync() { Debug.Assert(_status == StatusEnum.Uninitialized); if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(_location)) { var resolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_location); if (resolutions.Count > 0) { var resolution = resolutions.First(); _device = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(_location, resolution); if ((object)_device != null) { var values = AudioVideoCaptureDevice.GetSupportedPropertyValues(_location, KnownCameraAudioVideoProperties.VideoTorchMode); if (values.Contains((UInt32)VideoTorchMode.On)) { // Done, it looks like we have it! _status = StatusEnum.Ready; } else { _status = StatusEnum.CannotFindTorchOnDevice; _device.Dispose(); _device = null; } } else { _status = StatusEnum.CannotAccessCameraDevice; } } else { _status = StatusEnum.CannotFindValidResolutionForCamera; } } else { _status = StatusEnum.CannotFindBackCamera; } }
public void TurnOffFlashlight() { var sensorLocation = CameraSensorLocation.Back; try { // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { App.AvDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); } } catch (Exception) { } }
public void available(string options) { string callbackId; if (!TryDeserializeOptions(options, out callbackId)) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return; } var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (!supportedCameraModes.Contains((uint)VideoTorchMode.On)) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId); return; } this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK), callbackId); }
public static void TurnOnFlashlight(ToggleButton flashlight, AudioVideoCaptureDevice avDevice, CameraSensorLocation sensorLocation) { try { IReadOnlyList <object> 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); } flashlight.IsChecked = true; } catch (Exception ex) { MessageBox.Show("Turn On Flashlight " + ex.Message); } }
public FlashlightPage() { InitializeComponent(); //페이지 타이틀 PageTitle = string.Format("{0} - {1}", AppResources.ApplicationTitle, AppResources.Flashlight); ApplicationBarIconButton appbarClose = new ApplicationBarIconButton(); appbarClose.Text = AppResources.Home; appbarClose.IconUri = PathHelper.GetPath("appbar.home.variant.enter.png"); appbarClose.Click += appbarClose_Click; ApplicationBarIconButton appbarExit = new ApplicationBarIconButton(); appbarExit.Text = AppResources.Exit; appbarExit.IconUri = PathHelper.GetPath("appbar.door.leave.png"); appbarExit.Click += appbarExit_Click; ApplicationBar = new ApplicationBar(); ApplicationBar.Buttons.Add(appbarClose); ApplicationBar.Buttons.Add(appbarExit); WriteableBitmap source = BitmapFactory.New(0, 0).FromContent(PathHelper.GetFullPath("appbar.power.big.png").Substring(1)); PowerButtonImage.Source = source; var sensorLocation = CameraSensorLocation.Back; var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { //플래시 지원 기기 PowerButton.MouseEnter += PowerButton_MouseEnter; PowerButton.MouseLeave += PowerButton_MouseLeave; PowerButton.Tap += PowerButton_Tap; UseToggleButton.IsChecked = (bool)SettingHelper.Get(Constants.FLASHLIGHT_USE_TOGGLE_SWITCH); UseToggleButton.Checked += UseToggleButton_Checked; UseToggleButton.Unchecked += UseToggleButton_Unchecked; flickeringThread = new Thread(FlickeringThread); flickeringThread.Start(); InitializeFlashlight(); } else { //플래시 미지원 기기 FlickeringFrequencyHeader.Visibility = System.Windows.Visibility.Collapsed; FlickeringFrequency.Visibility = System.Windows.Visibility.Collapsed; UseToggleButton.Visibility = System.Windows.Visibility.Collapsed; PowerButton.MouseEnter += ((s, e) => { TurnOnButton(); }); PowerButton.MouseLeave += ((s, e) => { TurnOffButton(); }); PowerButton.Tap += ((s, e) => { SystemTray.IsVisible = false; ApplicationBar.IsVisible = false; FlashlightPanel.Visibility = System.Windows.Visibility.Visible; }); } Battery.GetDefault().RemainingChargePercentChanged += FlashlightPage_RemainingChargePercentChanged; BatteryRemainPercent.Text = Battery.GetDefault().RemainingChargePercent + "%"; }