protected virtual async Task CloseAsync() { _displayRequest.RequestRelease(); if (m_mediaCapture == null) { return; } UnregisterEventHandlers(); m_mediaCapture.RecordLimitationExceeded -= OnMediaCaptureRecordLimitationExceeded; m_mediaCapture.Failed -= OnMediaCaptureFailed; try { await m_mediaCapture.StopPreviewAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (m_isRecording) { await m_mediaCapture.StopRecordAsync(); } m_mediaCapture.Dispose(); m_mediaCapture = null; }
private async void initVideo() { try { if (camera != null) { // Cleanup MediaCapture object if (isPreviewing) { await camera.StopPreviewAsync(); isPreviewing = false; } camera.Dispose(); camera = null; } camera = new MediaCapture(); await camera.InitializeAsync(); previewElement.Source = camera; await camera.StartPreviewAsync(); isPreviewing = true; } catch (Exception ex) { Debug.WriteLine("Unable to initialize camera for audio/video mode: " + ex.Message); } }
private async Task ShutdownWebcamAsync() { if (null != _frameProcessingTimer) { _frameProcessingTimer.Cancel(); } if (null != _mediaCapture) { if (CameraStreamState.Streaming == _mediaCapture.CameraStreamState) { try { await _mediaCapture.StopPreviewAsync(); } catch { ; // Since we're going to destroy the MediaCapture object there's nothing to do here } } _mediaCapture.Dispose(); } _frameProcessingTimer = null; CameraPreview.Source = null; _mediaCapture = null; }
public async Task StopPreviewAsync() { if (!previewRunning) { return; } previewRunning = false; flashlight_btn.IsChecked = false; await StopFrameListenerAsync(); if (!(cameraCapture is null)) { try { await cameraCapture.StopPreviewAsync(); } catch (Exception) { } DisplayInformation.AutoRotationPreferences = DisplayOrientations.None; displayRequest.RequestRelease(); camera_ce.Source = null; VIEW_MODEL.MODEL.LampAvailable = false; cameraCapture?.Dispose(); cameraCapture = null; } }
private async Task ShutdownCameraAsync() { try { if (_threadPoolTimer != null) { _threadPoolTimer.Cancel(); } if (_mediaCapture != null) { if (_state == StreamingState.Streaming) { await _mediaCapture.StopPreviewAsync(); } _mediaCapture.Dispose(); } } catch (Exception) { } CameraPreview.Source = null; PaintingCanvas.Children.Clear(); _mediaCapture = null; _threadPoolTimer = null; }
/// <summary> /// Close the scanners and stop the preview. /// </summary> private async Task CloseScannerResourcesAsync() { claimedScanner?.Dispose(); claimedScanner = null; selectedScanner?.Dispose(); selectedScanner = null; SoftwareTriggerStarted = false; RaisePropertyChanged(nameof(SoftwareTriggerStarted)); if (IsPreviewing) { if (mediaCapture != null) { await mediaCapture.StopPreviewAsync(); mediaCapture.Dispose(); mediaCapture = null; } // Allow the display to go to sleep. displayRequest.RequestRelease(); IsPreviewing = false; RaisePropertyChanged(nameof(IsPreviewing)); } }
/// <summary> /// Returns a /// </summary> /// <param name="delayTime"></param> /// <returns></returns> public static IEnumerable <SoftwareBitmap> Snapshots(CaptureElement previewControl, int width, int height, Func <bool> stop = null) { _mediaCapture = new MediaCapture(); _mediaCapture.Failed += _mediaCapture_Failed; _mediaCapture.InitializeAsync().GetAwaiter().GetResult(); previewControl.Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, () => { previewControl.Source = _mediaCapture; }).GetAwaiter().GetResult(); _mediaCapture.StartPreviewAsync().GetAwaiter().GetResult(); _previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; width = (int)_previewProperties.Width; //ignore passed-in width and height and get the ones from the preview height = (int)_previewProperties.Height; while (true) { if ((stop != null) && stop()) { //cleanup _mediaCapture.StopPreviewAsync().GetAwaiter().GetResult(); _mediaCapture = null; previewControl.Dispatcher.TryRunAsync(CoreDispatcherPriority.Normal, () => { previewControl.Source = null; }).GetAwaiter().GetResult(); yield break; } yield return(CameraImage(previewControl, width, height)); } }
/// <summary> /// Initializes a new instance of the <see cref="MediaCaptureHelper"/> class. /// </summary> public MediaCaptureHelper() { // Skip the HW and lifetime related actions when in design mode if (DesignMode.DesignModeEnabled) { return; } Application.Current.Suspending += async(o, e) => { if (_captureManager == null) { return; } // Stop previewing when the app is being moved from the foreground var deferral = e.SuspendingOperation.GetDeferral(); await _captureManager.StopPreviewAsync(); _captureManager = null; deferral.Complete(); }; Application.Current.Resuming += (o, e) => { // Reset/restart on application resume ApplyDeviceSettings(); }; }
private async void CaptureStopButton_Click(object sender, RoutedEventArgs e) { try { _ = uploadProgressDialog.ShowAsync(); if (!IsCaptureEnabled) { IsCaptureEnabled = true; await _mediaRecording.StopAsync(); await _mediaRecording.FinishAsync(); await _mediaCapture.StopPreviewAsync(); await ViewModel.UploadVideoAsync(_video); await _video.DeleteAsync(); _mediaRecording = null; } } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } finally { uploadProgressDialog.Hide(); } }
private async Task StopPreviewAsync() { if (mediaCapture != null) { if (isRecording) { await mediaCapture.StopRecordAsync(); } if (isPreviewing) { await mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { captureElement.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; }); } return; }
public async void Stop() { await _camera.StopPreviewAsync(); _timer.Stop(); _state = StoppedState; }
public async Task StopPreviewAsync() { await _mediaCapture.StopPreviewAsync(); _captureElement.Source = null; _isPreviewing = false; }
private async Task CleanupCameraAsync() { if (mediaCapture != null) { if (isPreviewing) { await mediaCapture.StopPreviewAsync(); } await MainPage.runOnUIThread(async() => { if (lowLagCapture != null) { await lowLagCapture.FinishAsync(); } previewControl.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); }); } isPreviewing = false; }
//Zapremo predogled private async Task CleanupCameraAsync() { if (_capturingPreview != null) { if (_isPreviewing) { await _capturingPreview.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { //Terminiranje camera preview elementa camera_preview.Source = null; if (_request_to_display != null) { //Opustimo prošnjo za predogled try { _request_to_display.RequestRelease(); } catch { } } _capturingPreview.Dispose(); _capturingPreview = null; }); } }
private async Task CleanupCameraAsync() { if (mediaCapture != null) { if (isPreviewing) { await mediaCapture.StopPreviewAsync(); if (videoEffect != null) { await mediaCapture.RemoveEffectAsync(videoEffect); } } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { PreviewControl.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; }); } }
private void OnUnloaded(object sender, RoutedEventArgs e) { var action = mediaCapture.StopPreviewAsync(); mediaCapture.Failed -= mediaCapture_Failed; DisplayInformation.GetForCurrentView().OrientationChanged -= OnOrientationChanged; }
// webcamを止める処理 private async Task StopWebCameraAsync() { try { if (_frameProcessingTimer != null) { // 15fps毎で設定されているTimerを停止する _frameProcessingTimer.Cancel(); } if (_captureManager != null && _captureManager.CameraStreamState != CameraStreamState.Shutdown) { await _captureManager.StopPreviewAsync(); WebCamCaptureElement.Source = null; _captureManager.Dispose(); _captureManager = null; WebCamCaptureElement.Visibility = Visibility.Collapsed; } } catch (Exception ex) { Debug.Write("5"); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = $"error: {ex.Message}"); } }
public async Task CleanupCameraAsync() { if (mediaCapture != null) { qrAnalyzerCancellationTokenSource.Cancel(); qrAnalyzerCancellationTokenSource.Dispose(); if (isPreviewing) { await mediaCapture.StopPreviewAsync(); } isPreviewing = false; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.previewWindowElement.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; }); } }
private async Task CleanUpPreviewAndBitmapAsync() { if (_mediaCapture != null) { if (_isPreviewing) { await _mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Cleanup the UI ImagePreview.Source = null; if (_displayRequest != null) { // Allow the device screen to sleep now that the preview is stopped _displayRequest.RequestRelease(); } // Cleanup the media capture _mediaCapture.Dispose(); _mediaCapture = null; }); _isPreviewing = false; } if (_softwareBitmap != null) { _softwareBitmap.Dispose(); _softwareBitmap = null; } }
// closing process private async void closingScenario() { try { if (isRecording) { ShowStatusMessage("Stopping record"); await mediaCaptureMgr.StopRecordAsync(); isRecording = false; } if (isPreviewing) { ShowStatusMessage("Stopping record"); await mediaCaptureMgr.StopPreviewAsync(); isRecording = false; } if (mediaCaptureMgr != null) { ShowStatusMessage("Stopping Camera"); previewElement.Source = null; mediaCaptureMgr.Dispose(); } } catch (Exception e) { } }
/// <summary> /// Stops the preview and deactivates a display request, to allow the screen to go into power saving modes, and locks the UI /// </summary> /// <returns></returns> private async Task StopPreviewAsync() { try { isPreviewing = false; await mediaCapture.StopPreviewAsync(); } catch (Exception ex) { // Use the dispatcher because this method is sometimes called from non-UI threads. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Exception stopping preview. " + ex.Message, NotifyType.ErrorMessage); }); } // Use the dispatcher because this method is sometimes called from non-UI threads. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PreviewControl.Source = null; // Allow the device to sleep now that the preview is stopped. displayRequest.RequestRelease(); }); }
// Must be called on the UI thread private async Task DisposeCaptureAsync() { Preview.Source = null; if (autoFocus != null) { autoFocus.Dispose(); autoFocus = null; } MediaCapture mediaCapture; lock (this) { mediaCapture = this.mediaCapture; this.mediaCapture = null; } if (mediaCapture != null) { mediaCapture.Failed -= OnMediaCaptureFailed; await mediaCapture.StopPreviewAsync(); mediaCapture.Dispose(); } }
public async Task CleanUpAsync() { if (myCaptureElement != null) { myCaptureElement.Source = null; } if (MyMediaCapture != null) { try { await MyMediaCapture.StopPreviewAsync(); } catch (ObjectDisposedException o) { Debug.WriteLine(o.Message); } } if (MyMediaCapture != null) { try { MyMediaCapture.Dispose(); } catch (Exception e) { Debug.WriteLine(e.Message); } } }
public async Task CleanupCameraAsync() { try { if (_mediaCapture != null) { if (_isPreviewing) { await _mediaCapture.StopPreviewAsync(); } await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _captureElement.Source = null; if (_displayRequest != null) { _displayRequest.RequestRelease(); } _mediaCapture.Dispose(); _mediaCapture = null; }); } } catch (Exception ex) { // Eat the message Debug.WriteLine(ex.Message); } }
private async Task CloseCamera() { if (faceDetectionEffect != null && faceDetectionEffect.Enabled) { faceDetectionEffect.Enabled = false; faceDetectionEffect.FaceDetected -= FaceDetected; await capture.ClearEffectsAsync(MediaStreamType.VideoPreview); faceDetectionEffect = null; facesCanvas.Children.Clear(); } if (capture != null) { if (isPreviewing) { await capture.StopPreviewAsync(); isPreviewing = false; } capture.Dispose(); capture = null; } //if (photoFile != null) //{ // await photoFile.DeleteAsync(StorageDeleteOption.PermanentDelete); // photoFile = null; //} }
private async Task StopVideoAsync() { if (_mediaCapture != null && _isPreviewing) { try { _isPreviewing = false; await _mediaCapture.StopPreviewAsync(); } catch (Exception ex) { Debug.WriteLine("Exception when stopping the preview: {0}", ex.ToString()); } // Use the dispatcher because this method is sometimes called from non-UI threads await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Cleanup the UI CaptureElement.Source = null; // Allow the device screen to sleep now that the preview is stopped if (_displayRequest != null && _displayRequested) { _displayRequest.RequestRelease(); } }); _mediaCapture.Dispose(); _mediaCapture = null; } }
private async Task StopPreviewAsync() { _isPreviewing = false; await _mediaCapture.StopPreviewAsync(); PreviewControl.Source = null; }
private async void CleanupCameraAsync() { if (_mediaCapture != null) { if (_isPreviewing) { PreviewVisibility = false; await _mediaCapture.StopPreviewAsync(); } CaptureElement.Source = null; //await CoreDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => //{ if (_displayRequest != null) { _displayRequest.RequestRelease(); } if (_isRecording) { await _mediaCapture.StopRecordAsync(); } _mediaCapture.Dispose(); _mediaCapture = null; //}); } }
async Task CleanUpCaptureResourcesAsync() { if (captureElement != null) { captureElement.Source = null; } if (mediaCapture != null) { try { await mediaCapture.StopPreviewAsync(); } catch (Exception ex) { Debug.WriteLine(@" Error: ", ex.Message); } } if (mediaCapture != null) { try { mediaCapture.Dispose(); } catch (Exception ex) { Debug.WriteLine(@" Error: ", ex.Message); } } }
private async Task Init() { try { // ele = new CaptureElement(); _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(); previewElement.Source = _mediaCapture; await _mediaCapture.StartPreviewAsync(); await Task.Delay(TimeSpan.FromSeconds(5)); //await LaunchAppAsync("http:\\www.google.com"); await CapturePhoto(); await _mediaCapture.StopPreviewAsync(); Application.Current.Exit(); } catch (Exception e) { Application.Current.Exit(); } }