public void StopScanning() { if (stopped) return; Console.WriteLine("Stopping..."); //Try removing all existing outputs prior to closing the session try { while (session.Outputs.Length > 0) session.RemoveOutput (session.Outputs [0]); } catch { } //Try to remove all existing inputs prior to closing the session try { while (session.Inputs.Length > 0) session.RemoveInput (session.Inputs [0]); } catch { } if (session.Running) session.StopRunning(); stopped = true; }
void ToggleCaptureMode() { if (CaptureModeControl.SelectedSegment == (int)CaptureMode.Photo) { RecordButton.Enabled = false; sessionQueue.DispatchAsync(() => { // Remove the AVCaptureMovieFileOutput from the session because movie recording is // not supported with AVCaptureSessionPresetPhoto. Additionally, Live Photo // capture is not supported when an AVCaptureMovieFileOutput is connected to the session. session.BeginConfiguration(); session.RemoveOutput(MovieFileOutput); session.SessionPreset = AVCaptureSession.PresetPhoto; session.CommitConfiguration(); MovieFileOutput = null; if (photoOutput.IsLivePhotoCaptureSupported) { photoOutput.IsLivePhotoCaptureEnabled = true; DispatchQueue.MainQueue.DispatchAsync(() => { LivePhotoModeButton.Enabled = true; LivePhotoModeButton.Hidden = false; }); } }); } else if (CaptureModeControl.SelectedSegment == (int)CaptureMode.Movie) { LivePhotoModeButton.Hidden = true; sessionQueue.DispatchAsync(() => { var output = new AVCaptureMovieFileOutput(); if (session.CanAddOutput(output)) { session.BeginConfiguration(); session.AddOutput(output); session.SessionPreset = AVCaptureSession.PresetHigh; var connection = output.ConnectionFromMediaType(AVMediaType.Video); if (connection != null) { if (connection.SupportsVideoStabilization) { connection.PreferredVideoStabilizationMode = AVCaptureVideoStabilizationMode.Auto; } } session.CommitConfiguration(); MovieFileOutput = output; DispatchQueue.MainQueue.DispatchAsync(() => { RecordButton.Enabled = true; }); } }); } }
protected override void Dispose(bool disposing) { if (disposing) { RemoveObservers(); if (_session != null) { if (_session.Running) { _session.StopRunning(); } PreviewLayer.Session = null; if (_videoDeviceInput != null) { _session.RemoveInput(_videoDeviceInput); _videoDeviceInput.Dispose(); _videoDeviceInput = null; } if (_movieFileOutput != null) { _session.RemoveOutput(_movieFileOutput); _movieFileOutput.Dispose(); _movieFileOutput = null; } if (_stillImageOutput != null) { _session.RemoveOutput(_stillImageOutput); _stillImageOutput.Dispose(); _stillImageOutput = null; } _session.Dispose(); } } base.Dispose(disposing); }
public void StopScanning() { if (overlayView != null) { if (overlayView is ZXingDefaultOverlayView) { (overlayView as ZXingDefaultOverlayView).Destroy(); } overlayView = null; } if (stopped) { return; } Console.WriteLine("Stopping..."); if (outputRecorder != null) { outputRecorder.CancelTokenSource.Cancel(); } //Try removing all existing outputs prior to closing the session try { while (session.Outputs.Length > 0) { session.RemoveOutput(session.Outputs [0]); } } catch { } //Try to remove all existing inputs prior to closing the session try { while (session.Inputs.Length > 0) { session.RemoveInput(session.Inputs [0]); } } catch { } if (session.Running) { session.StopRunning(); } stopped = true; }
void SetCaptureType() { if (shouldCaptureFrames && captureSession.CanAddOutput(videoOutput)) { captureSession.AddOutput(videoOutput); // We want the buffers to be in portrait orientation otherwise they are // rotated by 90 degrees. Need to set this _after_ addOutput()! var captureConnection = videoOutput.ConnectionFromMediaType(AVMediaType.Video); captureConnection.VideoOrientation = AVCaptureVideoOrientation.Portrait; } else if (captureSession.Outputs.Contains(videoOutput)) { captureSession.RemoveOutput(videoOutput); } }
public void StopScanning() { if (_stopped) { return; } Console.WriteLine("Stopping..."); _outputRecorder?.CancelTokenSource.Cancel(); //Try removing all existing outputs prior to closing the session try { while (_session.Outputs.Length > 0) { _session.RemoveOutput(_session.Outputs[0]); } } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); } //Try to remove all existing inputs prior to closing the session try { while (_session.Inputs.Length > 0) { _session.RemoveInput(_session.Inputs[0]); } } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); } if (_session.Running) { _session.StopRunning(); } _stopped = true; }
void HideCameraPreview() { if (captureSession != null) { captureSession.StopRunning(); captureSession.RemoveOutput(stillImageOutput); captureSession.Dispose(); captureSession = null; } if (stillImageOutput != null) { stillImageOutput.Dispose(); stillImageOutput = null; } captureButton.Hidden = true; cancelButton.Hidden = true; }
private void _setupOutputMode(CameraOutputMode newCameraOutputMode, CameraOutputMode?oldCameraOutputMode) { captureSession.BeginConfiguration(); if (oldCameraOutputMode != null) { // remove current setting switch (oldCameraOutputMode) { case CameraOutputMode.StillImage: if (stillImageOutput != null) { captureSession.RemoveOutput(stillImageOutput); } break; case CameraOutputMode.VideoOnly: case CameraOutputMode.VideoWithMic: if (movieOutput != null) { captureSession.RemoveOutput(movieOutput); } if (oldCameraOutputMode == CameraOutputMode.VideoWithMic) { _removeMicInput(); } break; default: break; } } // configure new devices switch (newCameraOutputMode) { case CameraOutputMode.StillImage: if (stillImageOutput == null) { _setupOutputs(); } if (stillImageOutput != null) { captureSession.AddOutput(stillImageOutput); } break; case CameraOutputMode.VideoOnly: case CameraOutputMode.VideoWithMic: captureSession.AddOutput(_getMovieOutput()); if (newCameraOutputMode == CameraOutputMode.VideoWithMic) { var validMic = _deviceInputFromDevice(mic); if (validMic != null) { captureSession.AddInput(validMic); } } break; default: break; } captureSession.CommitConfiguration(); _updateCameraQualityMode(CameraOutputQuality); _orientationChanged(); }
void ToggleCaptureMode(UISegmentedControl captureModeControl) { if (captureModeControl.SelectedSegment == (int)AVCamCaptureMode.Photo) { //RecordButton.Enabled = false; sessionQueue.DispatchAsync(() => { /* * Remove the AVCaptureMovieFileOutput from the session because movie recording is * not supported with AVCaptureSessionPresetPhoto. Additionally, Live Photo * capture is not supported when an AVCaptureMovieFileOutput is connected to the session. */ session.BeginConfiguration(); session.RemoveOutput(movieFileOutput); session.SessionPreset = AVCaptureSession.PresetPhoto; session.CommitConfiguration(); movieFileOutput = null; if (photoOutput.IsLivePhotoCaptureSupported) { photoOutput.IsLivePhotoCaptureEnabled = true; //DispatchQueue.MainQueue.DispatchAsync(() => //{ // LivePhotoModeButton.Enabled = true; // LivePhotoModeButton.Hidden = false; //}); } //if (photoOutput.IsDepthDataDeliverySupported()) //{ // photoOutput.IsDepthDataDeliveryEnabled(true); // DispatchQueue.MainQueue.DispatchAsync(() => // { // DepthDataDeliveryButton.Hidden = false; // DepthDataDeliveryButton.Enabled = true; // }); //} }); } else if (captureModeControl.SelectedSegment == (int)AVCamCaptureMode.Movie) { //LivePhotoModeButton.Hidden = true; //DepthDataDeliveryButton.Hidden = true; sessionQueue.DispatchAsync(() => { var lMovieFileOutput = new AVCaptureMovieFileOutput(); if (session.CanAddOutput(lMovieFileOutput)) { session.BeginConfiguration(); session.AddOutput(lMovieFileOutput); session.SessionPreset = AVCaptureSession.PresetHigh; var connection = lMovieFileOutput.ConnectionFromMediaType(AVMediaType.Video); if (connection.SupportsVideoStabilization) { connection.PreferredVideoStabilizationMode = AVCaptureVideoStabilizationMode.Auto; } session.CommitConfiguration(); movieFileOutput = lMovieFileOutput; //DispatchQueue.MainQueue.DispatchAsync(() => //{ // RecordButton.Enabled = true; //}); } }); } }
public void StopScanning() { if (overlayView != null) { if (overlayView is ZXingDefaultOverlayView) { (overlayView as ZXingDefaultOverlayView).Destroy(); } overlayView = null; } if (stopped) { return; } Console.WriteLine("Stopping..."); if (outputRecorder != null) { outputRecorder.CancelTokenSource.Cancel(); } // Revert camera settings to original if (captureDevice != null && captureDevice.LockForConfiguration(out var err)) { captureDevice.FocusMode = captureDeviceOriginalConfig.FocusMode; captureDevice.ExposureMode = captureDeviceOriginalConfig.ExposureMode; captureDevice.WhiteBalanceMode = captureDeviceOriginalConfig.WhiteBalanceMode; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0) && captureDevice.AutoFocusRangeRestrictionSupported) { captureDevice.AutoFocusRangeRestriction = captureDeviceOriginalConfig.AutoFocusRangeRestriction; } if (captureDevice.FocusPointOfInterestSupported) { captureDevice.FocusPointOfInterest = captureDeviceOriginalConfig.FocusPointOfInterest; } if (captureDevice.ExposurePointOfInterestSupported) { captureDevice.ExposurePointOfInterest = captureDeviceOriginalConfig.ExposurePointOfInterest; } if (captureDevice.HasFlash) { captureDevice.FlashMode = captureDeviceOriginalConfig.FlashMode; } if (captureDevice.HasTorch) { captureDevice.TorchMode = captureDeviceOriginalConfig.TorchMode; } captureDevice.UnlockForConfiguration(); } //Try removing all existing outputs prior to closing the session try { while (session.Outputs.Length > 0) { session.RemoveOutput(session.Outputs[0]); } } catch { } //Try to remove all existing inputs prior to closing the session try { while (session.Inputs.Length > 0) { session.RemoveInput(session.Inputs[0]); } } catch { } if (session.Running) { session.StopRunning(); } stopped = true; }