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 Task StopRecordingAsync() { await mic.StopRecordingAsync(); mic.Dispose(); await sst.AsStream().FlushAsync(); sst.Dispose(); }
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { CameraButtons.ShutterKeyPressed -= OnButtonFullPress; if (!_appSettings.OperateUnderLockscreenSetting && _captureDevice != null) { _captureDevice.Dispose(); _captureDevice = null; } }
public void Term() { if (_status == StatusEnum.Ready) { _device.Dispose(); _device = null; } _status = StatusEnum.Uninitialized; }
private async Task StopRecordingAsync() { await mic.StopRecordingAsync(); mic.Dispose(); await sst.AsStream().FlushAsync(); SaveAudioClipToLocalStorage(); sst.Dispose(); }
static public void Sleep() { Enabled = isEnable; if (Enabled) { Disable(); } CamVideo.Dispose(); CamVideo = null; }
public override void Stop() { RunOnUIThread(() => { if (Preview != null) { Preview.UnloadCamera(); } Capture.PreviewFrameAvailable -= Capture_PreviewFrameAvailable; Capture.Dispose(); FrameAvailable = false; }); }
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; } }
/// <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 override void OnNavigatingFrom(NavigatingCancelEventArgs e) { _isNavigatingFrom = true; if (CameraIsRecording) { /* * var task = DoStopRecording(); * task.Start(); * task.Wait(); */ } TheMoveJoystick.StopJoystick(); ViewModel.AccelMovement.EnsureAccelerometerIsOnCommand.Execute(false); ViewModel.Speech.EnsureSpeechIsOn.Execute(false); ViewModel.AccelMovement.PropertyChanged -= AccelMovementOnPropertyChanged; _hackTimer.Stop(); if (_cam != null) { _cam.Dispose(); _cam = null; } _isNavigatingFrom = false; base.OnNavigatingFrom(e); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); captureDevice.Dispose(); }