private void cmdStartCapture_Click(object sender, RoutedEventArgs e) { if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { // Permission has been granted. // It's always safe to call this Stop(), even if no capture is running. // However, calling Start() while a capture is already running causes an error. capture.Stop(); // Get the default webcam. capture.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); if (capture.VideoCaptureDevice == null) { MessageBox.Show("Your computer does not have a video capture device."); } else { // Start a new capture. capture.Start(); // Map the live video to a VideoBrush. VideoBrush videoBrush = new VideoBrush(); videoBrush.Stretch = Stretch.Uniform; videoBrush.SetSource(capture); // Use the VideoBrush to paint the fill of a Rectangle. rectWebcamDisplay.Fill = videoBrush; } } }
// Set recording state: start recording. private void StartVideoRecording() { try { // Connect fileSink to captureSource. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); // Connect the input and output of fileSink. fileSink.CaptureSource = captureSource; fileSink.IsolatedStorageFileName = isoVideoFileName; } // Begin recording. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) { captureSource.Start(); } // Set the button states and the message. UpdateUI(ButtonState.Recording, "Recording..."); } // If recording fails, display an error. catch (Exception e) { this.Dispatcher.BeginInvoke(delegate() { txtDebug.Text = "ERROR: " + e.Message.ToString(); }); } }
private void WebCamDefault_Unloaded(object sender, RoutedEventArgs e) { try { _timerSend.Stop(); _timerReceive.Stop(); _captureSource.Stop(); _captureSource = null; } catch { } }
private void InitializeCaptureSource() { if (captureSource != null) { captureSource.Stop(); } captureSource = new CaptureSource(); captureSource.AudioCaptureDevice = (AudioCaptureDevice)listBoxAudioSources.SelectedItem; MediaDeviceConfig.SelectBestAudioFormat(captureSource.AudioCaptureDevice); captureSource.AudioCaptureDevice.DesiredFormat = captureSource.AudioCaptureDevice.SupportedFormats .First(format => format.BitsPerSample == AudioConstants.BitsPerSample && format.WaveFormat == WaveFormatType.Pcm && format.Channels == 1 && format.SamplesPerSecond == sampleRate); captureSource.AudioCaptureDevice.AudioFrameSize = AudioFormat.Default.MillisecondsPerFrame; // 20 milliseconds audioSink = new TestAudioSinkAdapter(captureSource, new NullAudioController()); audioSink.RawFrameAvailable += audioSink_RawFrameAvailable; audioSink.ProcessedFrameAvailable += audioSink_FrameArrived; ClientLogger.Debug("Checking device access."); if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { savedFramesForDebug = new List <byte[]>(); captureSource.Start(); ClientLogger.Debug("CaptureSource started."); } }
private void btCapture_Click(object sender, RoutedEventArgs e) { if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { VideoCaptureDevice webcam = cboWebcams.SelectedItem as VideoCaptureDevice; if (webcam == null) { CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); } if (webcam != null) { capture.Stop(); capture.VideoCaptureDevice = webcam; capture.Start(); VideoBrush brush = new VideoBrush(); brush.SetSource(capture); brush.Stretch = Stretch.Uniform; captureRect.Fill = brush; } else { MessageBox.Show("Nessuna webcam disponibile"); } } }
private void btnStop_Click(object sender, RoutedEventArgs e) { if (_captureSource != null && _captureSource.State == CaptureState.Started) { _captureSource.Stop(); } }
protected void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // Stop any active processes. if (_captureTimer != null) { _captureTimer.Stop(); } Stop(); if (CaptureSource != null) { CaptureSource.Stop(); } // Release all references to help with the double-reference problem that keeps stuff from getting garbage collected. CaptureSource = null; AudioSink = null; VideoSink = null; } _disposed = true; } }
public void ChangeCapturedDevices(AudioCaptureDevice audioDevice, VideoCaptureDevice videoDevice) { try { SelectedAudioDevice = audioDevice; SelectedVideoDevice = videoDevice; // Remember our initial capture state. bool wasCaptured = CaptureSource.State == CaptureState.Started; if (wasCaptured) { CaptureSource.Stop(); } CaptureSource.AudioCaptureDevice = audioDevice; CaptureSource.VideoCaptureDevice = videoDevice ?? CaptureSource.VideoCaptureDevice; ConfigureAudioCaptureDevice(CaptureSource.AudioCaptureDevice); ConfigureVideoCaptureDevice(CaptureSource.VideoCaptureDevice); // Restore capture state to how it originally was. if (wasCaptured) { CaptureSelectedInputDevices(); } } catch (Exception ex) { ClientLogger.ErrorException(ex, "Error updating captured devices"); MessageService.ShowErrorHint(ex.Message); } }
private void DoStartPlay(object obj) { CaptureDeviceConfiguration.RequestDeviceAccess(); if (captureSource != null) { captureSource.Stop(); captureSource = null; } // Desired format is 16kHz 16bit var queriedAudioFormats = from format in SelectedAudioDevice.SupportedFormats where format.SamplesPerSecond == 8000 && format.BitsPerSample == 16 && format.Channels == 1 select format; SelectedAudioDevice.DesiredFormat = queriedAudioFormats.FirstOrDefault(); SelectedAudioDevice.AudioFrameSize = 40; captureSource = new CaptureSource { AudioCaptureDevice = SelectedAudioDevice }; audioSink = new SpeexEncoderAudioSink(new Uri(@"http://" + ListenAddress)) { CaptureSource = captureSource }; captureSource.Start(); }
private void StopButton_Click(object sender, RoutedEventArgs e) { if ((CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) && myCaptureSource.VideoCaptureDevice != null) { myCaptureSource.Stop(); } }
private void StopButton_Click(object sender, RoutedEventArgs e) { // verify the VideoCaptureDevice is not null if (captureSource.VideoCaptureDevice != null) { captureSource.Stop(); } }
public void StopSendingAudioToRoom() { _captureSource.Stop(); _captureSource = null; _mediaController.Dispose(); _mediaController = null; _audioSinkAdapter = null; }
private void StartStopCapture() { try { // Start capturing if (captureSource.State != CaptureState.Started) { captureSource.Stop(); // Create video brush and fill the rectangle with it VideoBrush vidBrush = new VideoBrush(); vidBrush.Stretch = Stretch.Uniform; vidBrush.SetSource(captureSource); WebcamVideo.Fill = vidBrush; // Ask user for permission if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { captureSource.Start(); } this.BtnCapture.Content = "Stop Fun"; // Start AR this.CanvasARContent.Visibility = System.Windows.Visibility.Visible; this.CanvasLogo.Visibility = System.Windows.Visibility.Collapsed; doAR = true; } else { // Stop AR doAR = false; this.CanvasARContent.Visibility = System.Windows.Visibility.Collapsed; this.CanvasLogo.Visibility = System.Windows.Visibility.Visible; // Stop capturing captureSource.Stop(); this.BtnCapture.Content = "Start Fun"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error using webcam", MessageBoxButton.OK); throw; } }
// Set recording state: start recording. private void StartVideoRecording() { try { // Connect fileSink to captureSource. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); DateTime dNow = DateTime.Now; string sVidName = dNow.Year.ToString() + RscUtils.pad60(dNow.Month) + RscUtils.pad60(dNow.Day) + "_" + RscUtils.pad60(dNow.Hour) + RscUtils.pad60(dNow.Minute) + RscUtils.pad60(dNow.Second); // Connect the input and output of fileSink. fileSink.CaptureSource = captureSource; fileSink.IsolatedStorageFileName = (RscKnownFolders.GetMediaPath("DCVID") + "\\" + sVidName + ".mp4").Substring(3); } // Begin recording. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) { captureSource.Start(); } // Set the button states and the message. UpdateUI(ButtonState.Recording, "Recording..."); BtnBk.Fill = new SolidColorBrush(Colors.Green); } // If recording fails, display an error. catch (Exception /*e*/) { this.Dispatcher.BeginInvoke(delegate() { //txtDebug.Text = "ERROR: " + e.Message.ToString(); BtnBk.Fill = new SolidColorBrush(Colors.Red); }); } }
private void btnWebCamStart_Click(object sender, RoutedEventArgs e) { if (_captureSource != null & blnStart == false) { try { _captureSource.Stop(); // stop whatever device may be capturing _captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); _captureSource.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice(); } catch { _captureSource = null; } try { if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { _captureSource.Start(); if (_captureSource.State == System.Windows.Media.CaptureState.Started) { // capture the current frame and add it to our observable collection _images.Clear(); _captureSource.CaptureImageAsync(); _timerImg.Start(); blnStart = true; btnWebCamStart.Content = "WebCam STOP"; } return; } } catch { } } else { _captureSource.Stop(); blnStart = false; btnWebCamStart.Content = "WebCam START"; } }
private void stop_Click(object sender, EventArgs e) { if (videoRecorder != null && videoRecorder.State == CaptureState.Started) { videoRecorder.Stop(); videoRecorder = null; fileWriter = null; videoContainer.Fill = new SolidColorBrush(Colors.Gray); } }
public void ReleaseCaptureSource() { Deployment.Current.Dispatcher.BeginInvoke(() => { if (_captureSource != null && _captureSource.State == CaptureState.Started) { _captureSource.Stop(); } }); }
private void StartVideoRecording() { try { if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); fileSink.CaptureSource = captureSource; fileSink.IsolatedStorageFileName = isoVideoFileName; } if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) { captureSource.Start(); } } catch { } }
private void DisposeVideoRecorder() { if (_captureSource != null) { // Stop _captureSource if it is running. if (_captureSource.VideoCaptureDevice != null && _captureSource.State == CaptureState.Started) { _captureSource.Stop(); } // Remove the event handlers for capturesource and the shutter button. _captureSource.CaptureFailed -= OnCaptureFailed; _captureSource.CaptureImageCompleted -= OnThumbCompleted; // Remove the video recording objects. _captureSource = null; _videoCaptureDevice = null; _fileSink = null; ViewfinderBrush = null; } }
private void HandleCaptureError(Exception ex) { ClientLogger.DebugException(ex, "Capture devices failed"); RaiseCaptureFailed(); if (CaptureSource != null) { if (CaptureSource.State == CaptureState.Started) { CaptureSource.Stop(); } CaptureSource.VideoCaptureDevice = null; } }
private void BtnCapture_Click(object sender, RoutedEventArgs e) { try { // 开始捕捉 if (captureSource.State != CaptureState.Started) { captureSource.Stop(); // 创建 video brush 并填充到 rectangle VideoBrush vidBrush = new VideoBrush(); vidBrush.Stretch = Stretch.UniformToFill; vidBrush.SetSource(captureSource); focusRectangle.Viewport.Fill = vidBrush; // 询问是否接入 if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { focusRectangle.Viewport.MaxHeight = focusRectangle.Viewport.MaxWidth = ZoomInOut.Maximum = 400; ZoomInOut.Value = 270; ZoomInOut.Minimum = 16; ZoomInOut.ValueChanged += new RoutedPropertyChangedEventHandler <double>(focusRectangle.ViewportSlider_ValueChanged); captureSource.Start(); BtnCapture.Text = "打开摄像头"; BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = true; } } else { captureSource.Stop(); BtnCapture.Text = "关闭摄像头"; BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = false; } } catch (Exception ex) { Utils.ShowMessageBox("Error using webcam", ex.Message); } }
/// <summary> /// Sets recording state: start recording /// </summary> private void StartVideoRecording() { try { if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started)) { captureSource.Stop(); fileSink.CaptureSource = captureSource; filePath = System.IO.Path.Combine("/" + LocalFolderName + "/", defaultFileName); using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isoFile.DirectoryExists(LocalFolderName)) { isoFile.CreateDirectory(LocalFolderName); } if (isoFile.FileExists(filePath)) { isoFile.DeleteFile(filePath); } } fileSink.IsolatedStorageFileName = filePath; } if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) { captureSource.Start(); } this.UpdateUI(VideoState.Recording); } catch (Exception) { this.result = new VideoResult(TaskResult.None); this.NavigateBack(); } }
public void StartRecording(Rectangle viewfinderRectangle, string filePath) { InitializeVideoRecorder(viewfinderRectangle); // Connect fileSink to captureSource. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); // Connect the input and output of fileSink. fileSink.CaptureSource = captureSource; fileSink.IsolatedStorageFileName = filePath; } // Begin recording. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Stopped) { captureSource.Start(); } }
void ToggleDevice(object sender, RoutedEventArgs e) { if (on) { on = false; source.Stop(); toggleButton.Content = "Turn On"; this.videoSurface.Fill = new SolidColorBrush(Colors.White); } else { if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { if (this.container.Child is TextBox) { this.container.Child = this.videoSurface; } try { source.Start(); var brush = new VideoBrush(); brush.SetSource(source); this.videoSurface.Fill = brush; //toggleButton.Content = "Turn Off"; var canvas = new Canvas(); canvas.Width = 70; canvas.Height = 50; var text = new TextBlock(); text.Text = "Turn Off"; canvas.Children.Add(text); text.SetValue(Canvas.LeftProperty, 5d); text.SetValue(Canvas.TopProperty, 5d); canvas.Background = brush; toggleButton.Content = canvas; on = true; } catch (InvalidOperationException ex) { this.HandleDeviceInUseError(ex); } } } }
public void StopTimingTest() { Status = ""; _captureSource.Stop(); if (_mediaElement != null) { _mediaElement.Stop(); _mediaElement = null; } if (_mediaController != null) { _mediaController.Dispose(); } }
public void stop() { if (captureSource != null) { // Stop captureSource if it is running. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } // Remove the event handler for captureSource. captureSource.CaptureFailed -= OnCaptureFailed; // Remove the video recording objects. captureSource = null; videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; System.Diagnostics.Debug.WriteLine("Stopped"); _isRunning = false; } }
private void InitializeCaptureSource() { ClientLogger.Debug("AudioLoopbackTest:InitializeCaptureSource()"); if (_captureSource != null) { _captureSource.Stop(); } _captureSource = new CaptureSource(); _captureSource.AudioCaptureDevice = (AudioCaptureDevice)lstAudioInputDevices.SelectedItem; _captureSource.VideoCaptureDevice = (VideoCaptureDevice)lstVideoInputDevices.SelectedItem; _mediaElement = new MediaElement(); _audioStreamSource = new TestAudioStreamSource(this); // Set the audio properties. if (_captureSource.AudioCaptureDevice != null) { MediaDeviceConfig.SelectBestAudioFormat(_captureSource.AudioCaptureDevice); if (_captureSource.AudioCaptureDevice.DesiredFormat != null) { _captureSource.AudioCaptureDevice.AudioFrameSize = _audioFormat.MillisecondsPerFrame; // 20 milliseconds _audioSink = new TestAudioSinkAdapter(_captureSource, new NullAudioController()); _audioSink.RawFrameAvailable += audioSink_RawFrameAvailable; _audioSink.ProcessedFrameAvailable += audioSink_FrameArrived; ClientLogger.Debug("CaptureSource initialized."); } else { ClientLogger.Debug("No suitable audio format was found."); } ClientLogger.Debug("Checking device access."); if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) { ClientLogger.Debug("AudioLoopbackTest CaptureSource starting with audio device {0}, video device {1}.", _captureSource.AudioCaptureDevice.FriendlyName, _captureSource.VideoCaptureDevice.FriendlyName); _captureSource.Start(); ClientLogger.Debug("CaptureSource started; setting media element source."); _mediaElement.SetSource(_audioStreamSource); ClientLogger.Debug("MediaElement source set; telling media element to play."); _mediaElement.Play(); } } else { // Do something more here eventually, once we figure out what the user experience should be. ClientLogger.Debug("No audio capture device was found."); } }
// Start video playback. private void StartPlayback_Click(object sender, EventArgs e) { // Avoid duplicate taps. StartPlayback.IsEnabled = false; // Start video playback when the file stream exists. if (_isoVideoFile != null) { VideoPlayer.Play(); } // Start the video for the first time. else { // Stop the capture source. _captureSource.Stop(); // Remove VideoBrush from the tree. viewfinderRectangle.Fill = null; // Create the file stream and attach it to the MediaElement. _isoVideoFile = new IsolatedStorageFileStream(IsoVideoFileName, FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication()); VideoPlayer.SetSource(_isoVideoFile); // Add an event handler for the end of playback. VideoPlayer.MediaEnded += VideoPlayerMediaEnded; // Start video playback. VideoPlayer.Play(); } // Set the button state and the message. UpdateUI(ButtonState.Playback, "Playback started."); }
private void btnRecord_Click(object sender, RoutedEventArgs e) { if (btnRecord.Content.ToString() == "Start") { btnPlay.IsEnabled = false; btnRecord.Content = "Stop"; recordedAudio.Clear(); captureSource.Start(); } else { captureSource.Stop(); btnRecord.Content = "Start"; btnPlay.IsEnabled = true; } }
private void btnStop_Click(object sender, RoutedEventArgs e) { try { _captureSource.Stop(); mediaElement.Stop(); foreach (var vm in _mediaServerVms) { vm.Disconnect(); } btnStart.IsEnabled = true; btnStop.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }