public async Task StopScanningAsync() { if (stopping) { return; } stopping = true; isAnalyzing = false; try { displayRequest?.RequestRelease(); } catch (Exception ex) { Console.WriteLine($"Release Request Failed: {ex}"); } try { if (IsTorchOn) { Torch(false); } if (isMediaCaptureInitialized) { await mediaCapture.StopPreviewAsync(); } if (UseCustomOverlay && CustomOverlay != null) { gridCustomOverlay.Children.Remove(CustomOverlay); } } catch { } finally { //second execution from sample will crash if the object is not properly disposed (always on mobile, sometimes on desktop) if (mediaCapture != null) { mediaCapture.Dispose(); } } //this solves a crash occuring when the user rotates the screen after the QR scanning is closed displayInformation.OrientationChanged -= DisplayInformation_OrientationChanged; if (timerPreview != null) { timerPreview.Change(Timeout.Infinite, Timeout.Infinite); } stopping = false; }
public static void PrivateDisplayCall(bool shouldActivate) { if (_displayAlwaysOnRequest == null) { return; } try { if (shouldActivate) { _displayAlwaysOnRequest.RequestActive(); } else { _displayAlwaysOnRequest.RequestRelease(); } } catch { } }
private async Task StopPreviewAsync() { try { await mediaCapture.StopPreviewAsync(); isPreviewing = false; } catch (Exception ex) { // error when stopping preview } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { photoPreview.Source = null; displayRequest.RequestRelease(); }); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (timer != null) { timer.Tick -= Timer_Tick; timer.Stop(); timer = null; } ForegroundEnergyManager.RecentEnergyUsageIncreased -= ForegroundEnergyManager_RecentEnergyUsageIncreased; ForegroundEnergyManager.RecentEnergyUsageReturnedToLow -= ForegroundEnergyManager_RecentEnergyUsageReturnedToLow; isEnergyManagerConnected = false; if (displayRequest != null) { displayRequest.RequestRelease(); } navigationHelper.OnNavigatedFrom(e); }
private async Task CleanupCameraAsync() { if (mediaCapture != null) { if (isPreviewing) { await mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PreviewControl.Source = null; displayRequest?.RequestRelease(); mediaCapture.Dispose(); mediaCapture = null; }); } }
private async Task CleanupCameraAsync() { if (mediaCapture != null) { await mediaCapture.StopPreviewAsync(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MyWebcam.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; }); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { var roaming = ApplicationData.Current.RoamingSettings; var offset = sv.VerticalOffset / sv.ScrollableHeight; if (roaming.Values.ContainsKey(scrollOffsetKey)) { roaming.Values[scrollOffsetKey] = offset; } else { roaming.Values.Add(scrollOffsetKey, offset); } if (display != null) { display.RequestRelease(); display = null; } base.OnNavigatedFrom(e); }
private void OnDestroy() { UnityEngine.WSA.Application.InvokeOnUIThread(() => { if (displayRequest != null) { try { displayRequest.RequestRelease(); Debug.Log("Display request released."); } catch (Exception e) { Debug.LogError($"Error releasing display request: {e.Message}"); } displayRequest = null; } }, true); }
public static void StopDisplayRequest() { if (displayRequest != null) { try { // This call de-activates the display-required request. If successful, the screen // might be turned off automatically due to a user inactivity, depending on the // power policy settings of the system. The requestRelease method throws an exception // if it is called before a successful requestActive call on this object. displayRequest.RequestRelease(); drCount -= 1; //rootPage.NotifyUser("Display request released (" + drCount + ")", NotifyType.StatusMessage); } catch /*(Exception ex)*/ { //rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage); } } }
/// <summary> /// Stops the preview and deactivates a display request, to allow the screen to go into power saving modes /// </summary> /// <returns></returns> private async Task StopPreviewAsync() { //////////////songyao//////////////// timer.Tick -= TimeTickHandler; timer.Stop(); ///////////////////////////////////// // Stop the preview _isPreviewing = false; await _mediaCapture.StopPreviewAsync(); // Use the dispatcher because this method is sometimes called from non-UI threads await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Cleanup the UI PreviewControl.Source = null; // Allow the device screen to sleep now that the preview is stopped _displayRequest.RequestRelease(); }); }
/// <summary> /// Stops the camera preview and releases all resources /// </summary> /// <returns></returns> public async Task CleanupCameraAsync() { if (_mediaCapture != null) { if (_isDetecting) { // Disable detection _faceDetectionEffect.Enabled = false; // Unregister the event handler _faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected; // Remove the effect from the preview stream await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview); // Clear the member variable that held the effect instance _faceDetectionEffect = null; _isDetecting = false; } if (IsPreviewing) { await _mediaCapture.StopPreviewAsync(); IsPreviewing = false; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CameraPreview.Source = null; if (_displayRequest != null) { _displayRequest.RequestRelease(); } _mediaCapture.Dispose(); _mediaCapture = null; }); } }
/// <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() { _isPreviewing = false; await _mediaCapture.StopPreviewAsync(); // Use the dispatcher because this method is sometimes called from non-UI threads await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (Const.DISPLAY_PREVIEW) { PreviewControl.Source = null; } else { PreviewControlFake.Source = null; } // Allow the device to sleep now that the preview is stopped _displayRequest.RequestRelease(); }); }
/// <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() { _isPreviewing = false; try { await _mediaCapture?.StopPreviewAsync(); } catch (Exception ex) { OnDetectCameraError(ex); } // Use the dispatcher because this method is sometimes called from non-UI threads await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PreviewControl.Source = null; try { // Allow the device to sleep now that the preview is stopped _displayRequest.RequestRelease(); } catch (Exception ex) { OnDetectCameraError(ex); } }); }
protected async override void OnNavigatedFrom(NavigationEventArgs e) { // Cancel all tasks that are running _ctsVideoMonitor.Cancel(); // Wait for the main video monitoring task to complete await _faceMonitoringTask; // Allows the screen to go to sleep again when you leave this page _displayRequest.RequestRelease(); _displayRequest = null; // Stop and clean up the video feed await _mediaCapture.StopPreviewAsync(); videoPreview.Source = null; _mediaCapture.Dispose(); _mediaCapture = null; base.OnNavigatedFrom(e); }
static void Dispose() { Timer.Stop(); display.RequestRelease(); for (int i = 0; i < 48; i++) { if (buff[i] != null) { buff[i].Stop(); buff[i].Visibility = Visibility.Collapsed; } } PSB.canB.Visibility = Visibility.Collapsed; PSB.canA.Visibility = Visibility.Collapsed; PSB.bor.Visibility = Visibility.Collapsed; Main.NotifyStop(); #if phone ApplicationView.GetForCurrentView().ExitFullScreenMode(); DisplayInformation.AutoRotationPreferences = DisplayOrientations.None; #endif }
/// <summary> /// End navigate to page. /// </summary> public void NavigateFrom() { try { m_DisplayRequest.RequestRelease(); } catch { } ShowPlaylistButton = true; if (VideoSource != null) { ChangePlayback(PlaybackState.Pause, false); } var view = ApplicationView.GetForCurrentView(); if (view.IsFullScreenMode) { view.ExitFullScreenMode(); } }
public async Task StopScanAsync() { _scanStarted = false; if (this.timer != null && this.timer.IsEnabled) { this.timer.Stop(); } if (mediaCapture != null) { await mediaCapture.StopPreviewAsync(); PreviewControl.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; } }
private async Task CleanupCameraAsync() { if (_mediaCapture == null) { return; } await _mediaCapture.StopPreviewAsync(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { webcamPreview.Source = null; _displayRequest?.RequestRelease(); }); _mediaCapture.Dispose(); _mediaCapture = null; buttonLaunchWebcam.Content = "Launch webcam"; _isPreviewing = false; }
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (wc != null) { wc = null; } if (dispRequest != null) { // 用户暂停了视频,则不需要保持屏幕的点亮状态 dispRequest.RequestRelease(); // 停用显示请求 dispRequest = null; } time.Stop(); if (hr != null) { hr.EndHeart(); hr = null; } stack_Comment.Children.Clear(); }
/// <summary> /// Stops the preview and deactivates a display request, to allow the screen to go into power saving modes /// </summary> /// <returns></returns> private async Task StopPreviewAsync() { if (_mediaCapture == null) { return; } // Stop the preview _previewProperties = null; await _mediaCapture.StopPreviewAsync(); // Use the dispatcher because this method is sometimes called from non-UI threads await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Cleanup the UI PreviewControl.Source = null; // Allow the device screen to sleep now that the preview is stopped _displayRequest.RequestRelease(); }); }
private async Task CleanupCameraAsync() { Debug.WriteLine("CleanupCameraAsync"); try { RenderFPS = 0; // Clean up the media capture if (_mediaCapture != null) { if (_isPreviewing) { try { await _mediaCapture.StopPreviewAsync(); } catch (Exception e) { Debug.WriteLine("CleanupCamera: " + e.Message); } } await DispatcherHelper.RunAsync(() => { CaptureElement cap = new CaptureElement(); cap.Source = null; _appModel.OutputCaptureElement = cap; if (_isPreviewing) { _displayrequest.RequestRelease(); } MediaCapture m = _mediaCapture; _mediaCapture = null; m.Dispose(); _isPreviewing = false; }); } } catch (Exception ex) { Debug.WriteLine($"CleanupCameraAsync: {ex.Message}"); } }
static void CreatBlack() { bor = new Border(); bor.Width = Window.Current.Bounds.Width; bor.Height = Window.Current.Bounds.Height; bor.Background = new SolidColorBrush(Colors.Black); bor.PointerPressed += (o, e) => { long t = DateTime.Now.Ticks; if (t - time > Component.presstime) { count = 0; } time = t; }; bor.PointerReleased += (o, e) => { long t = DateTime.Now.Ticks; if (t - time < Component.presstime) { time = t; count++; if (count >= 2) { bor.Visibility = Visibility.Collapsed; count = 0; display.RequestRelease(); #if phone ApplicationView.GetForCurrentView().ExitFullScreenMode(); #endif } } else { count = 0; } }; bor.Visibility = Visibility.Collapsed; parent.Children.Add(bor); }
private async void btnPublish_Unchecked(object sender, RoutedEventArgs e) { try { if (_displayRequest != null) { _displayRequest.RequestRelease(); _displayRequest = null; } if (_clockTimer != null) { _clockTimer.Change(Timeout.Infinite, Timeout.Infinite); _clockTimer = null; tbClock.Text = ""; } if (_deviceManager.IsPublishing) { if (_deviceManager.EnableLowLatency && _lowlagCapture != null) { await _lowlagCapture.FinishAsync(); } else { await _deviceManager.CurrentCapture.StopRecordAsync(); } } _deviceManager.IsPreviewing = false; await _deviceManager.CurrentCapture.StartPreviewAsync(); await _deviceManager.SaveHistoryAsync(); } catch (Exception Ex) { } _deviceManager.IsPublishing = false; }
private async Task CleanupCameraAsync() { if (_mediaCapture != null) { if (_isPreviewing) { await _mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { CapPreview.Source = null; if (_displayRequest != null) { _displayRequest.RequestRelease(); } _mediaCapture.Dispose(); _mediaCapture = null; }); } }
private async Task CleanupCameraAsync() { if (captureManager != null) { if (_isPreviewing) { await captureManager.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { myCaptureElement.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } captureManager.Dispose(); captureManager = null; }); } }
//------------------------------------Tracking-------------------------------------// private void startStop() { if (!_tracking) //start tracking! { _tracking = true; _startButton.Content = "Trip beenden"; _currentTrackingProcess = new Trip(_routeName, System.Environment.TickCount); if (_currentTrackingProcess.CountPoints > 0) { setPosition(_lastPosition); } } else //stop tracking & open tripSummaryPage! { _tracking = false; _stopTracking = true; _dispRequest.RequestRelease(); _obdThread.Cancel(); Frame.Navigate(typeof(TripSummaryPage), new Tuple <Trip, IConsumption>(_currentTrackingProcess, _consumptionCalculator)); } }
private void UpdateLockScreenPrevention(MediaElementState currentState) { if (currentState != MediaElementState.Playing) { if (_request == null) { return; } _request.RequestRelease(); _request = null; return; } if (_request != null) { return; } _request = new DisplayRequest(); _request.RequestActive(); }
/// <summary> /// Cleanup camera instances /// </summary> /// <returns></returns> private async Task CleanupCameraAsync() { Debug.WriteLine("CleanupCameraAsync"); if (_isInitialized) { if (_isPreviewing) { await StopPreviewAsync(); } // Allow the device to sleep now that the preview is stopped _displayRequest.RequestRelease(); } _selectedFrameSource = null; if (_mediaCapture != null) { _mediaCapture.Dispose(); _mediaCapture = null; _isInitialized = false; } }
private void ScreenOn(bool isOn) { if (!ViewModel.Settings.ScreenOn) { return; } if (!isOn && dispRequest == null) { return; } if (!isOn) { dispRequest.RequestRelease(); dispRequest = null; return; } if (dispRequest == null) { dispRequest = new DisplayRequest(); dispRequest.RequestActive(); } }
private async void Reste_button_Click(object sender, RoutedEventArgs e) { if (_mediaCapture != null) { if (_isPreviewing) { await _mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PreviewControl.Source = null; if (_displayRequest != null) { _displayRequest.RequestRelease(); } _mediaCapture.Dispose(); _mediaCapture = null; }); } }