private async Task InitializeCamera()
        {
            if (Options.UseFrontCameraIfAvailable.HasValue && Options.UseFrontCameraIfAvailable.Value)
            {
                try
                {
                    var frontCameraCaptureResolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Front);
                    var resolution = GetResolution(frontCameraCaptureResolutions.OrderBy(r => r.Width * r.Height));
                    _photoCamera = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(CameraSensorLocation.Front, resolution);
                }
                catch (Exception ex)
                {
                    MobileBarcodeScanner.Log("Failed to create front facing camera: {0}", ex);
                }
            }

            MobileBarcodeScanner.Log("InitializeCamera");

            if (_photoCamera == null)
            {
                var backCameraCaptureResolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
                var resolution = GetResolution(backCameraCaptureResolutions.OrderBy(r => r.Width * r.Height));
                _photoCamera = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(CameraSensorLocation.Back, resolution);
            }

            IsAnalyzing = true;

            OnPhotoCameraInitialized(this, new CameraOperationCompletedEventArgs(true, null));

            MobileBarcodeScanner.Log("Wired up Initizialied");
        }
Example #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");
            }
        }
Example #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");
            }
        }
Example #4
0
        public async void switchOff(string jsonArgs)
        {
            if (hasFlashlight())
            {
                if (this.Device == null)
                {
                    this.Device = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                                                                          AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back)[0]);
                }
                bool disposed = false;
                try
                {
                    this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                }
                catch (ObjectDisposedException ignore)
                {
                    // may be thrown when the app is paused/resumed
                    disposed = true;
                }
                if (disposed)
                {
                    this.Device = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                                                                          AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back)[0]);

                    this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                }
                DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
            }
            else
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Device is not capable of using the flashlight. Please test with flashlight.available()"));
            }
        }
Example #5
0
        private async Task <AudioVideoCaptureDevice> GetCaptureDevice()
        {
            AudioVideoCaptureDevice captureDevice =
                await
                AudioVideoCaptureDevice.OpenAsync(_sensorLocation,
                                                  AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_sensorLocation)
                                                  .First());

            return(captureDevice);
        }
        private async void FlashLight_Checked(object sender, RoutedEventArgs e)
        {
            if (!_cameraIsOn)
            {
                _avDevice = await AudioVideoCaptureDevice.OpenAsync(SensorLocation,
                                                                    AudioVideoCaptureDevice.GetAvailableCaptureResolutions(SensorLocation).First());

                _cameraIsOn = true;
            }
            if (_cameraIsOn)
            {
                Common.TurnOnFlashlight(FlashLight, _avDevice, SensorLocation);
            }
        }
Example #7
0
        async void InitializeFlashlight()
        {
            if (App.AvDevice == null)
            {
                var sensorLocation = CameraSensorLocation.Back;
                // get the AudioViceoCaptureDevice
                App.AvDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
                                                                       AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());
            }

            if (UseToggleButton.IsChecked == true)
            {
                TurnOnButton();
            }
        }
Example #8
0
 public async void switchOff(string jsonArgs)
 {
     if (hasFlashlight())
     {
         if (this.Device == null)
         {
             this.Device = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                                                                   AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back)[0]);
         }
         this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
         DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
     }
     else
     {
         DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Device is not capable of using the flashlight. Please test with flashlight.available()"));
     }
 }
        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;
            }
        }
Example #10
0
        private async void SetupFlash()
        {
            try
            {
                ButtonVisibility     = Visibility.Collapsed;
                InitializeVisibility = Visibility.Visible;

                // get the AudioViceoCaptureDevice
                _avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                                                                    AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());

                ButtonVisibility     = Visibility.Visible;
                InitializeVisibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
            }
        }
Example #11
0
        private async void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _tutorial.IsOpen = AppSetting.IsShowTutorial();

            //Starting checking
            if (!_checkState.IsEnabled)
            {
                _checkState.Start();
            }

            CoverStoryboard.Begin();

            #region Check NetWork State

            Common.SetStateNetWork(Wifi, WifiState, Model.Wifi.Enabled());
            Common.SetStateNetWork(Cellular, CellularState, Model.Cellular.Enabled());
            //Common.SetStateNetWork(Bluetooth, BluetoothState, Model.Bluetooth.Enabled().Result);
            Common.SetStateNetWork(Location, LocationState, Model.Location.Enabled());
            Common.SetStateNetWork(Airplane, AirplaneState, Model.Airplane.Enabled());

            #endregion

            if (NavigationContext.QueryString.TryGetValue(Key, out _value))
            {
                if (_value == ShortcutValue.FlashLight)
                {
                    if (!_cameraIsOn)
                    {
                        _avDevice = await AudioVideoCaptureDevice.OpenAsync(SensorLocation,
                                                                            AudioVideoCaptureDevice.GetAvailableCaptureResolutions(SensorLocation).First());

                        _cameraIsOn = true;
                    }
                    if (_cameraIsOn)
                    {
                        Common.TurnOnFlashlight(FlashLight, _avDevice, SensorLocation);
                    }
                }
            }
        }
Example #12
0
        private void Summary()
        {
            lblMsg.Text = "";

            // 获取电话上的可用摄像头
            foreach (CameraSensorLocation csl in AudioVideoCaptureDevice.AvailableSensorLocations)
            {
                // Back 或 Front
                lblMsg.Text += "摄像头:" + csl.ToString();
                lblMsg.Text += System.Environment.NewLine;


                // 摄像所支持的分辨率
                lblMsg.Text += "摄像的可用分辨率:";
                foreach (var size in AudioVideoCaptureDevice.GetAvailableCaptureResolutions(csl))
                {
                    lblMsg.Text += size.Width + "*" + size.Height + " ";
                }
                lblMsg.Text += System.Environment.NewLine;
                lblMsg.Text += System.Environment.NewLine;
            }


            lblMsg.Text += "终端所支持的视频编码格式:";
            foreach (CameraCaptureVideoFormat format in AudioVideoCaptureDevice.SupportedVideoEncodingFormats)
            {
                lblMsg.Text += format.ToString() + " ";
            }
            lblMsg.Text += System.Environment.NewLine;


            lblMsg.Text += "终端所支持的音频编码格式:";
            foreach (CameraCaptureAudioFormat format in AudioVideoCaptureDevice.SupportedAudioEncodingFormats)
            {
                lblMsg.Text += format.ToString() + " ";
            }
            lblMsg.Text += System.Environment.NewLine;
        }
Example #13
0
        private async void VideoRecord_Loaded(object sender, RoutedEventArgs e)
        {
            // 一些概述类的说明
            Summary();

            // 是否有后置摄像头
            if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                // 获取后置摄像头摄像时的可用分辨率
                IReadOnlyList <Windows.Foundation.Size> supportedResolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
                Windows.Foundation.Size resolution = supportedResolutions[0];

                try
                {
                    // 让后置摄像头以指定的分辨率捕获镜头内容
                    _captureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

                    // AudioVideoCaptureDevice.OpenForVideoOnlyAsync() - 仅捕获视频
                    // AudioVideoCaptureDevice.OpenForAudioOnlyAsync() - 仅捕获音频

                    // 录像失败时触发的事件
                    _captureDevice.RecordingFailed += _captureDevice_RecordingFailed;


                    /*
                     * SetCaptureResolutionAsync() - 设置摄像的分辨率
                     * CaptureResolution - 获取当前摄像的分辨率
                     * VideoEncodingFormat - 当前的视频编码格式
                     * AudioEncodingFormat - 当前的音频编码格式
                     * FocusRegion - 对焦区域
                     * SensorLocation - 当前摄像头的位置(CameraSensorLocation 枚举:Back 或 Front)
                     * SensorRotationInDegrees - 获取摄像头传感器相对于屏幕的旋转度数
                     * FocusAsync() - 自动对焦
                     * ResetFocusAsync() - 复位对焦
                     */


                    /*
                     * KnownCameraAudioVideoProperties 属性集包括
                     *     VideoFrameRate - 每秒抓取的视频帧数
                     *     H264EncodingProfile - H264 编码的 profile(H264EncoderProfile 枚举)
                     *     H264EncodingLevel - H264 编码的 level(H264EncoderLevel 枚举)
                     *     H264EnableKeyframes - 是否启用关键帧
                     *     H264QuantizationParameter - QP 值,低的 QP 会保留大部分空间的详细信息,从而达到最佳质量,高的 QP 会在一定程度上造成质量的损失,但能帮助编码器实现较低的比特率
                     *     H264RequestDropNextNFrames - 指定编码器应丢弃的帧数
                     *     H264RequestIdrFrame - 此属性设置为 true 时,系统请求编码流程进行瞬时解码刷新(IDR)
                     *     UnmuteAudioWhileRecording - 此属性设置为 true 时,能在记录期间为音频取消静音
                     *     VideoTorchMode - 录像时如何使用闪光灯(VideoTorchMode 枚举:Off, Auto, On)
                     *     VideoTorchPower - 录像时闪光灯的亮度,无单位且不同设备上的值不同
                     */
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.H264EncodingProfile, H264EncoderProfile.Baseline);


                    /*
                     * KnownCameraGeneralProperties 属性集包括
                     *     AutoFocusRange - 自动对焦的范围(AutoFocusRange 枚举,包括微距等)
                     *     EncodeWithOrientation - 视频编码时的旋转角度,必须是 90 的倍数
                     *     SpecifiedCaptureOrientation -  元数据中的旋转角度,必须是 90 的倍数
                     *     IsShutterSoundEnabledByUser - 用户是否启用了快门声音,只读
                     *     IsShutterSoundRequiredForRegion - 运行应用程序的区域是否需要快门声音(有些区域为了保护隐私,要求照相或录像必须要有快门声音),只读
                     *     PlayShutterSoundOnCapture - 指定捕获时是否播放快门声音
                     *     ManualFocusPosition - 手动对焦的位置
                     */
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Normal);
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, _captureDevice.SensorRotationInDegrees);


                    // 获取指定属性的值
                    // _captureDevice.GetProperty(KnownCameraGeneralProperties.IsShutterSoundEnabledByUser);

                    /*
                     * 获取指定的范围类属性在当前摄像头中所允许的值的范围
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264QuantizationParameter);

                    /*
                     * 获取指定的值类属性在当前摄像头中所允许的值的列表
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264EncodingProfile);

                    // 实时显示捕获的内容
                    videoBrush.SetSource(_captureDevice); // 扩展方法来自:Microsoft.Devices.CameraVideoBrushExtensions

                    rt.Angle = _captureDevice.SensorRotationInDegrees;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有后置摄像头");
            }
        }
Example #14
0
        private async void StartCameraAsync()
        {
            _cam = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());

            TheVideoBrush.SetSource(_cam);
        }
 private async Task <AudioVideoCaptureDevice> GetCaptureDevice()
 {
     return(await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(sensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First()));
 }
Example #16
0
        private async Task <AudioVideoCaptureDevice> GetCaptureDevice()
        {
            if (this.captureDevice == null)
            {
                this.captureDevice = await AudioVideoCaptureDevice.OpenAsync(SensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(SensorLocation).First());
            }

            return(this.captureDevice);
        }