/// <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"); } }
/// <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 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()")); } }
private async Task <AudioVideoCaptureDevice> GetCaptureDevice() { if (this.captureDevice == null) { this.captureDevice = await AudioVideoCaptureDevice.OpenAsync(SensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(SensorLocation).First()); } return(this.captureDevice); }
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); } }
public async void InitializeVideoRecorder() { try { if (_videoCaptureDevice == null) { var applicationFolder = ApplicationData.Current.LocalFolder; _outputFile = await applicationFolder.CreateFileAsync(_isoVideoFileName, CreationCollisionOption.ReplaceExisting); _stream = await _outputFile.OpenAsync(FileAccessMode.ReadWrite); _videoCaptureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, new Size(320, 240)); _videoCaptureDevice.VideoEncodingFormat = CameraCaptureVideoFormat.H264; // Add eventhandlers for captureSource. _videoCaptureDevice.RecordingFailed += RecordingFailed; // Initialize the camera if it exists on the device. if (_videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. _videoRecorderBrush = new VideoBrush(); _videoRecorderBrush.SetSource(_videoCaptureDevice); // Display the viewfinder image on the rectangle. ViewfinderRectangle.Fill = _videoRecorderBrush; // Set the button state and the message. UpdateUi(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the device. UpdateUi(ButtonState.CameraNotSupported, "A camera is not supported on this device."); } } } catch (Exception) { if (_videoCaptureDevice != null) { _videoCaptureDevice.Dispose(); } // Disable buttons when the camera is not supported by the device. UpdateUi(ButtonState.CameraNotSupported, "Camera malfunction occurred."); } }
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(); } }
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()")); } }
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) { } }
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); } } } }
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("没有后置摄像头"); } }
private async void StartCameraAsync() { _cam = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()); TheVideoBrush.SetSource(_cam); }