Beispiel #1
0
 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.";
     }
 }
Beispiel #2
0
        /// <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");
            }
        }
Beispiel #3
0
        /// <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");
            }
        }
        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)
            {
            }
        }
Beispiel #5
0
        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;
                }
            }
        }
Beispiel #6
0
        private async void StartFlash(string callbackId)
        {
            try
            {
                var device = await this.GetCaptureDevice();

                device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                   AudioVideoCaptureDevice.GetSupportedPropertyRange(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
            }
            catch
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), callbackId);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        /// <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();
        }