void ButtonPause_Clicked(object sender, EventArgs e) { if (rec != null) { rec.Pause(); labelRecStatus.Text = "paused"; } }
public void PauseResume(object arg) { if (_recorder.State == RecorderState.Recording) { _recorder.Pause(); StatusText = AppResources.PausedStatusText; PauseResumeButtonText = AppResources.ResumeButtonText; } else { _recorder.Resume(); StatusText = AppResources.RecordingStatusText; PauseResumeButtonText = AppResources.PauseButtonText; } }
public MainViewModel() { _timer = new Timer(1000); _timer.Elapsed += TimerOnElapsed; #region Commands ScreenShotCommand = new DelegateCommand(CaptureScreenShot, () => _canScreenShot); RecordCommand = new DelegateCommand(() => { if (ReadyToRecord) { StartRecording(); } else { StopRecording(); } }, () => _canRecord); RefreshCommand = new DelegateCommand(() => { VideoViewModel.RefreshVideoSources(); VideoViewModel.RefreshCodecs(); AudioViewModel.RefreshAudioSources(); Status = $"{VideoViewModel.AvailableCodecs.Count} Encoder(s) and " + $"{AudioViewModel.AvailableRecordingSources.Count + AudioViewModel.AvailableLoopbackSources.Count - 2} AudioDevice(s) found"; }); OpenOutputFolderCommand = new DelegateCommand(() => Process.Start("explorer.exe", OutPath)); PauseCommand = new DelegateCommand(() => { if (IsPaused) { _recorder.Start(); _timer.Start(); IsPaused = false; Status = "Recording..."; } else { _recorder.Pause(); _timer.Stop(); IsPaused = true; Status = "Paused"; } }, () => !ReadyToRecord && _recorder != null); SelectOutputFolderCommand = new DelegateCommand(() => { var dlg = new FolderBrowserDialog { SelectedPath = OutPath, Description = "Select Output Folder" }; if (dlg.ShowDialog() != DialogResult.OK) { return; } OutPath = dlg.SelectedPath; Settings.Default.OutputPath = dlg.SelectedPath; Settings.Default.Save(); }); #endregion //Populate Available Codecs, Audio and Video Sources ComboBoxes RefreshCommand.Execute(null); AudioViewModel.PropertyChanged += (Sender, Args) => { if (Args.PropertyName == nameof(AudioViewModel.SelectedRecordingSource) || Args.PropertyName == nameof(AudioViewModel.SelectedLoopbackSource)) { CheckFunctionalityAvailability(); } }; VideoViewModel.PropertyChanged += (Sender, Args) => { if (Args.PropertyName == nameof(VideoViewModel.SelectedVideoSource)) { CheckFunctionalityAvailability(); } }; _cursor = new MouseCursor(OthersViewModel.Cursor); OthersViewModel.PropertyChanged += (Sender, Args) => { switch (Args.PropertyName) { case nameof(OthersViewModel.RegionSelectorVisible): VideoViewModel.RefreshVideoSources(); break; case nameof(OthersViewModel.Cursor): _cursor.Include = OthersViewModel.Cursor; break; } }; // If Output Dircetory is not set. Set it to Documents\Captura\ if (string.IsNullOrWhiteSpace(OutPath)) { OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\"); } // Create the Output Directory if it does not exist if (!Directory.Exists(OutPath)) { Directory.CreateDirectory(OutPath); } Settings.Default.OutputPath = OutPath; Settings.Default.Save(); }
public MainWindow() { InitializeComponent(); Instance = this; #region Init Timer DTimer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, (s, e) => { Seconds++; if (Seconds == 60) { Seconds = 0; Minutes++; } // If Capture Duration is set if (Duration > 0 && (Minutes * 60 + Seconds >= Duration)) { StopRecording(); SystemSounds.Exclamation.Play(); // SystemTray Notification if (SystemTray.Visible) { SystemTray.ShowBalloonTip(3000, "Capture Completed", string.Format("Capture Completed in {0} seconds", OtherSettings.CaptureDuration), System.Windows.Forms.ToolTipIcon.None); } } TimeManager.Content = string.Format("{0:D2}:{1:D2}", Minutes, Seconds); }, TimeManager.Dispatcher) { IsEnabled = false }; #endregion //Populate Available Codecs, Audio and Video Sources ComboBoxes Refresh(); #region Command Bindings CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) => { var dlg = new FolderBrowserDialog() { SelectedPath = OutPath.Text, Title = "Select Output Folder" }; if (dlg.ShowDialog().Value) { OutPath.Text = dlg.SelectedPath; Settings.Default.OutputPath = dlg.SelectedPath; Settings.Default.Save(); } })); CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => StartRecording(), (s, e) => e.CanExecute = ReadyToRecord)); CommandBindings.Add(new CommandBinding(ApplicationCommands.Stop, (s, e) => StopRecording(), (s, e) => e.CanExecute = !ReadyToRecord)); CommandBindings.Add(new CommandBinding(NavigationCommands.Refresh, (s, e) => Refresh())); CommandBindings.Add(new CommandBinding(PauseCommand, (s, e) => { Recorder.Pause(); DTimer.Stop(); PauseButton.Command = ResumeCommand; RotationEffect.Angle = 90; Status.Content = "Paused"; PauseButton.ToolTip = "Pause"; }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null)); CommandBindings.Add(new CommandBinding(ResumeCommand, (s, e) => { Recorder.Start(); DTimer.Start(); PauseButton.Command = PauseCommand; RotationEffect.Angle = 0; Status.Content = "Recording..."; PauseButton.ToolTip = "Resume"; }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null)); #endregion #region SystemTray SystemTray = new NotifyIcon() { Visible = false, Text = "Captura", Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location) }; SystemTray.Click += (s, e) => { SystemTray.Visible = false; Show(); WindowState = WindowState.Normal; }; StateChanged += (s, e) => { if (WindowState == WindowState.Minimized && OtherSettings.MinimizeToSysTray) { Hide(); SystemTray.Visible = true; } }; #endregion #region KeyHook KeyHook = new KeyboardHookList(this); KeyHook.Register(KeyCode.R, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt, () => Dispatcher.Invoke(() => ToggleRecorderState())); KeyHook.Register(KeyCode.S, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt, () => Dispatcher.Invoke(() => CaptureScreenShot())); #endregion // If Output Dircetory is not set. Set it to Documents\Captura\ if (string.IsNullOrWhiteSpace(OutPath.Text)) { OutPath.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\"); } // Create the Output Directory if it does not exist if (!Directory.Exists(OutPath.Text)) { Directory.CreateDirectory(OutPath.Text); } Settings.Default.OutputPath = OutPath.Text; Settings.Default.Save(); Closed += (s, e) => App.Current.Shutdown(); cursor = new MouseCursor(OtherSettings.IncludeCursor); OtherSettings.Instance.PropertyChanged += (s, e) => { if (e.PropertyName == "_IncludeCursor") { cursor.Include = OtherSettings.IncludeCursor; } }; }