private async Task MicStartAsync(string foundbiteName) { mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync(); mic.AudioEncodingFormat = CameraCaptureAudioFormat.Aac; sst = await SetUpAudioFileForSavingRecordedAudioAsync(foundbiteName); }
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); }
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 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."; } }
/// <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 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()")); } }
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()")); } }
void RecordingFailed(AudioVideoCaptureDevice sender, CaptureFailedEventArgs args) { Dispatcher.BeginInvoke(delegate { txtDebug.Text = "ERROR: " + args.ErrorCode; }); }
// 录像失败 void _captureDevice_RecordingFailed(AudioVideoCaptureDevice sender, CaptureFailedEventArgs args) { this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show("error: " + args.ErrorCode.ToString()); }); }
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) { } }
/// <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"); }
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"); }
async static public Task <bool> Init() { if (isExist) { return(true); } for (int i = 0; i < 5; i++) { try { CamVideo = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(CameraSensorLocation.Back, new Windows.Foundation.Size(640, 480)); CamVideo.GetProperty(KnownCameraAudioVideoProperties.VideoTorchMode); break; } catch { } } if (CamVideo == null) { MessageBox.Show(AppResources.Text_Error_Light, AppResources.Text_Error_Title, MessageBoxButton.OK); } return(isExist); }
/// <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"); } }
private async void InitializeCaptureDevice() { captureDevice = await GetCaptureDevice(); IReadOnlyList <object> supportedModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); flashSupported = supportedModes.ToList().Contains((UInt32)VideoTorchMode.On); }
private async Task <AudioVideoCaptureDevice> GetCaptureDevice() { if (this.captureDevice == null) { this.captureDevice = await AudioVideoCaptureDevice.OpenAsync(SensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(SensorLocation).First()); } return(this.captureDevice); }
/// <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(); }
private async void FlashButton_Click(object sender, RoutedEventArgs e) { var sensorLocation = CameraSensorLocation.Back; try { if (!flashEnabled) { if (this.Device == null) { // get the AudioViceoCaptureDevice this.Device = await AudioVideoCaptureDevice.OpenAsync(sensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First()); } // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On); // set flash power to maxinum this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max); } else { turnWhiteScreen(true); } EllipseLight.Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255)); flashEnabled = true; } else { // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode); if (this.Device != null && supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.Off)) { this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); } else { turnWhiteScreen(false); } flashEnabled = false; EllipseLight.Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)); } } catch (Exception ex) { // Flashlight isn't supported on this device, instead show a White Screen as the flash light turnWhiteScreen(true); } }
public void Term() { if (_status == StatusEnum.Ready) { _device.Dispose(); _device = null; } _status = StatusEnum.Uninitialized; }
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { CameraButtons.ShutterKeyPressed -= OnButtonFullPress; if (!_appSettings.OperateUnderLockscreenSetting && _captureDevice != null) { _captureDevice.Dispose(); _captureDevice = null; } }
private async Task <AudioVideoCaptureDevice> GetCaptureDevice() { AudioVideoCaptureDevice captureDevice = await AudioVideoCaptureDevice.OpenAsync(_sensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_sensorLocation) .First()); return(captureDevice); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (_dev != null) { _dev.Dispose(); _dev = null; } base.OnNavigatedFrom(e); }
public static void TurnOffFlashlight(ToggleButton flashlight, AudioVideoCaptureDevice avDevice) { try { avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off); flashlight.IsChecked = false; } catch (Exception ex) { MessageBox.Show("Turn Off Flashlight " + ex.Message); } }
public CameraStreamSource(AudioVideoCaptureDevice dev, Windows.Foundation.Size size) { _frameWidth = (int)size.Width; _frameHeight = (int)size.Height; _dev = dev; _cameraData = new int[_frameWidth * _frameHeight]; _frameBufferSize = _frameWidth * _frameHeight * _framePixelSize; _cameraFilteredData = new byte[_frameBufferSize]; _frameStreamSize = _frameBufferSize * 4; //Number of frames for buffering : 4 works well. _frameStream = new MemoryStream(_frameStreamSize); }
static public void Sleep() { Enabled = isEnable; if (Enabled) { Disable(); } CamVideo.Dispose(); CamVideo = null; }
public async Task StartRecordingAsync(IRandomAccessStream stream) { ThrowIfDisposed(); if (IsRecording || _isStarting) return; _isStarting = true; _device = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync(); //_device.AudioEncodingFormat = CameraCaptureAudioFormat.Aac; // AAC is default _recordingStream = stream; await _device.StartRecordingToStreamAsync(_recordingStream); IsRecording = true; _isStarting = false; }
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 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 Task StartRecordingAsync() { _mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync(); _mic.AudioEncodingFormat = CameraCaptureAudioFormat.Amr; try { await CreateFileStreamForAudioAsync(recordAudioFileName); await _mic.StartRecordingToStreamAsync(_randomAccessStream); } catch (Exception ex) { throw ex; } }
private void DisposeVideoRecorder() { if (_videoCaptureDevice != null) { // Remove the event handlers for capturesource and the shutter button. _videoCaptureDevice.RecordingFailed -= RecordingFailed; _videoCaptureDevice.Dispose(); // Remove the video recording objects. _videoCaptureDevice = null; _videoRecorderBrush = null; } }
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."); } }
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); } }
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 Task StartRecordingAsync() { _mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync(); _mic.AudioEncodingFormat = CameraCaptureAudioFormat.Amr; try { await CreateFileStreamForAudioAsync(recordAudioFileName); await _mic.StartRecordingToStreamAsync(_randomAccessStream); } catch (Exception ex) { throw ex; } }
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 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 static Size GetInitialResolution(CameraSensorLocation location, int videoWidth, int videoHeight) { var resolutions = AudioVideoCaptureDevice.GetAvailablePreviewResolutions(location); // find the closest resolution if (videoWidth > 0 || videoHeight > 0) { var closest = new List <Size>(); var distance = -1; foreach (var res in resolutions) { if (distance < 0) { closest.Add(res); distance = GetSizeDistance(res, videoWidth, videoHeight); } else { var d = GetSizeDistance(res, videoWidth, videoHeight); if (d == distance) { closest.Add(res); } else if (d < distance) { closest = new List <Size>(); closest.Add(res); distance = d; } } } resolutions = closest; } if (resolutions.Count == 0) { var error = "The camera does not support any resolutions."; Log.Error(error); throw new Exception(error); } return(resolutions[0]); }
/// <summary> /// Stops the camera and capture process /// </summary> public void Stop() { IsAnalyzing = false; doCancel = true; if (_timer != null && _timer.IsEnabled) { _timer.Stop(); } if (_photoCamera != null) { CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed; _photoCamera.Dispose(); _photoCamera = null; } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); try { if (this._isNewPageInstance) { // If the device already exists, we have done all the work already if (this._device == null) { // First, make sure that this device has a back camera this._device = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()); // Since there is a camera (since we haven't thrown an exception yet), check if the back camera has a torch var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchMode); // Does the back camera allow us to turn on the torch if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { // We can turn on the torch, so set up for it this.SetupDevice(); } else { // Can't turn on torch, so just show white screen instead this.SetupWhiteScreen(); } } } } catch (Exception) { // We crashed, most likely because there is no back camera. Show white screen instead this.SetupWhiteScreen(); } this._isNewPageInstance = false; }
/// <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"); }
async void ActivateCamera() { if (_dev == null) { if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back)) { _dev = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()); _videoBrush = new VideoBrush(); _videoBrush.SetSource(_dev); MainPage_OrientationChanged(null, null); this.videoRect.Fill = _videoBrush; StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile storageFile = await localFolder.CreateFileAsync("CameraMovie.mp4", CreationCollisionOption.ReplaceExisting); _path = storageFile.Path; _sst = await storageFile.OpenAsync(FileAccessMode.ReadWrite); await _dev.StartRecordingToStreamAsync(_sst); } } }
private void CameraOff() { if (camera != null) { camera.Dispose(); camera = null; } }
/// <summary> /// Stops the camera and capture process /// </summary> public void Stop() { IsAnalyzing = false; doCancel = true; if (_timer != null && _timer.IsEnabled) _timer.Stop(); if (_photoCamera != null) { CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed; _photoCamera.Dispose(); _photoCamera = null; } }
private async Task MicStartAsync(string foundbiteName) { mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync(); mic.AudioEncodingFormat = CameraCaptureAudioFormat.Aac; sst = await SetUpAudioFileForSavingRecordedAudioAsync(foundbiteName); }
// 录像失败 void _captureDevice_RecordingFailed(AudioVideoCaptureDevice sender, CaptureFailedEventArgs args) { this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show("error: " + args.ErrorCode.ToString()); }); }
public override void OnResume(object sender, ActivatedEventArgs e) { this.Device = null; }
private void SetupWhiteScreen() { this._device = null; // Hide system tray to increase amount of white screen shown SystemTray.IsVisible = false; ((SolidColorBrush)this.LayoutRoot.Background).Color = Colors.White; this.LayoutRoot.Background.Opacity = 1.0; // Background opacity set by slider this.sldTorchPower.Visibility = Visibility.Visible; this.sldTorchPower.Maximum = 255; this.sldTorchPower.Minimum = 0; this.sldTorchPower.Value = this.sldTorchPower.Maximum; this.btnTorchMode.IsChecked = true; }
private void Button_Click_1(object sender, System.Windows.RoutedEventArgs e) { if (_dev != null) { _dev.StopRecordingAsync().Completed = (IAsyncAction action, Windows.Foundation.AsyncStatus status) => { _dev.Dispose(); _dev = null; new MediaPlayerLauncher() { Media = new Uri(_path, UriKind.Relative), }.Show(); }; } }
private async Task initCamera(CameraSensorLocation sensorLocation) { Windows.Foundation.Size res = new Windows.Foundation.Size(MediaElementWidth, MediaElementHeight); CameraOff(); camera = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(sensorLocation, res); await camera.SetPreviewResolutionAsync(res); frameBitmap = new WriteableBitmap((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height); }
private async Task DisposeMembers() { if (_device != null) { _device.Dispose(); _device = null; } if (_recordingStream != null) { await _recordingStream.FlushAsync(); _recordingStream.Dispose(); _recordingStream = null; } }
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"); }
private async void StartInternal() { var locations = GetCameraSensorLocations(); var location = locations[0]; if (CaptureArgs.DeviceNumber.HasValue && CaptureArgs.DeviceNumber.Value < locations.Length) { location = locations[CaptureArgs.DeviceNumber.Value]; } else if (DesiredDeviceNumber.HasValue && DesiredDeviceNumber.Value < locations.Length) { location = locations[DesiredDeviceNumber.Value]; DeviceNumber = DesiredDeviceNumber.Value; } Label = GetCameraSensorLocationName(location); Capture = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(location, GetInitialResolution(location, CaptureArgs.Width, CaptureArgs.Height)); Capture.SetProperty(KnownCameraAudioVideoProperties.VideoFrameRate, CaptureArgs.FrameRate); Capture.PreviewFrameAvailable += Capture_PreviewFrameAvailable; if (Preview != null) { Preview.LoadCamera(Capture); RunOnUIThread(() => { SetRotation(Page.Orientation); Preview.Rotate(BufferRotate); }); } RunOnUIThread(() => { XnaTimer = new DispatcherTimer(); XnaTimer.Interval = TimeSpan.FromMilliseconds(10); XnaTimer.Tick += XnaTimer_Tick; XnaTimer.Start(); }); }
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("没有后置摄像头"); } }