void OnPauseExecute() { if (RecorderState == RecorderState.Paused) { _systemTray.HideNotification(); _recorder.Start(); _timing?.Start(); _timer?.Start(); RecorderState = RecorderState.Recording; Status.LocalizationKey = nameof(LanguageManager.Recording); } else { _recorder.Stop(); _timer?.Stop(); _timing?.Pause(); RecorderState = RecorderState.Paused; Status.LocalizationKey = nameof(LanguageManager.Paused); _systemTray.ShowTextNotification(Loc.Paused, null); } }
public static async void StartWithTimeout(this IRecorder recorder, int millisecondsTimeout) { recorder.Start(); await Task.Delay(millisecondsTimeout); recorder.Stop(); }
public void StartRecoding(String savePath) { FileSavePath = savePath + "BAR-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".avi"; //图像 IImageProvider imgProvider = null; try { imgProvider = GetImageProvider(); } catch (Exception e) { MessageBox.Show(e.Message); imgProvider?.Dispose(); return; } //声音 IAudioProvider audioProvider = null; try { Settings.Audio.Enabled = true; if (Settings.Audio.Enabled && !Settings.Audio.SeparateFilePerSource) { audioProvider = _audioSource.GetMixedAudioProvider(); } } catch (Exception e) { MessageBox.Show(e.Message); _audioSource?.Dispose(); return; } //视频写入 IVideoFileWriter videoEncoder; try { videoEncoder = GetVideoFileWriterWithPreview(imgProvider, audioProvider); } catch (Exception e) { MessageBox.Show(e.Message); imgProvider?.Dispose(); audioProvider?.Dispose(); return; } _recorder = new Recorder(videoEncoder, imgProvider, Settings.Video.FrameRate, audioProvider); _recorder.Start(); }
/// <summary> /// 点击录音 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AudioRecord_Click(object sender, EventArgs e) { if (false == Directory.Exists(RecorderPath)) { Directory.CreateDirectory(RecorderPath); } if (AudioDeviceCount == 0) { //if (_audiosource.availablerecordingsources.count <= 0&& _audiosource.availableloopbacksources.count <= 0) //{ // system.windows.forms.messagebox.show("未找到音频设备."); // return; //} System.Windows.Forms.MessageBox.Show("未找到音频设备."); return; } if (audioRecording == false) { audioRecording = true; IAudioProvider audioProvider = null; try { audioProvider = _audioSource.GetMixedAudioProvider(); } catch (Exception ex) { ServiceProvider.MessageProvider.ShowException(ex, ex.Message); } var fileName = Path.Combine(RecorderPath, "BAR-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".wav"); _recorder = new Recorder(WaveItem.Instance.GetAudioFileWriter(fileName, audioProvider?.WaveFormat, 50), audioProvider); _recorder.Start(); recordingStopwatch.Reset(); ScreenRecordTimer.Start(); recordingStopwatch.Start(); ScreenRecord.Enabled = false; // 禁用/启用 ScreenRecord.Visible = false; AudioRecord.Enabled = false; AudioRecord.Visible = false; StopRecording.Enabled = true; StopRecording.Visible = true; RecordTimeTick.Visible = true; } }
public void StartAudioRecording(string file = "") { try { if (ApplicationVM.ProfileVM.AudioConfigurationVM.LoopbackRecording) { if (recorder == null) { recorder = AudioManager.CreateRecorder(defaultCodec, true); recorder.SampleAvailableEvent += SampleAvailableEventHandler; } recorder.Start(file); } } catch { } }
public void StartRecording(string filePath) { _cursor = new MouseCursor(true); _currentFileName = FolderFileUtil.GetFullFilePath(filePath) + ".avi"; var imgProvider = GetImageProvider(); var videoEncoder = GetVideoFileWriter(imgProvider); _recorder = new Recorder(videoEncoder, imgProvider, int.Parse(ConfigurationManager.AppSettings["VideoFrameRate"]), null); _recorder.RecordingStopped += (s, E) => { OnStopped(); if (E?.Error == null) { return; } }; _recorder.Start(0); }
public bool StartRecording() { try { recorder = Shared.Extensions.Instance.Recorders .FirstOrDefault(t => t.Metadata.Name.Equals("Wave") && t.Metadata.Version.Equals("1.0"))? .Value; } catch (Exception ex) { systemLog.Error(LOG_PREFIX + " Could not load transcriber extension", ex); } if (recorder != null) { systemLog.Debug(LOG_PREFIX + " Start recording"); recorder.Start(Id); recording = true; } return(recording); }
public async void Record(object arg) { await InitializeRecorder(); if (App.SettingsHelper.RecordInBackground) { LocationHelper.StartTracking(); } _recorder.Start(); _isRecording = true; StatusText = AppResources.RecordingStatusText; PauseResumeButtonText = AppResources.PauseButtonText; if (App.SettingsHelper.AddLocation) { IsLocationEnabled = true; LocationText = AppResources.LocationFindingText; _location = await LocationHelper.GetLocationAsync(); if (_location != null) { LocationText = AppResources.AddressFindingText; var address = await LocationHelper.GetAddressAsync(_location); LocationText = !string.IsNullOrWhiteSpace(address) ? address : AppResources.AddressUnidentifiedText; } else { LocationText = AppResources.LocationNotFoundText; } } }
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; } }; }
MainViewModel() { _timer = new Timer(1000); _timer.Elapsed += TimerOnElapsed; #region Commands ScreenShotCommand = new DelegateCommand(CaptureScreenShot); RecordCommand = new DelegateCommand(() => { if (RecorderState == RecorderState.NotRecording) { StartRecording(); } else { StopRecording(); } }); RefreshCommand = new DelegateCommand(() => { VideoViewModel.RefreshVideoSources(); VideoViewModel.RefreshCodecs(); AudioViewModel.AudioSource.Refresh(); Status = "Refreshed"; }); OpenOutputFolderCommand = new DelegateCommand(() => { EnsureOutPath(); Process.Start(Settings.OutPath); }); PauseCommand = new DelegateCommand(() => { if (RecorderState == RecorderState.Paused) { _recorder.Start(); _timer.Start(); RecorderState = RecorderState.Recording; Status = "Recording..."; } else { _recorder.Stop(); _timer.Stop(); RecorderState = RecorderState.Paused; Status = "Paused"; SystemTrayManager.ShowNotification("Recording Paused", " ", 500, null); } }, false); SelectOutputFolderCommand = new DelegateCommand(() => { var dlg = new FolderBrowserDialog { SelectedPath = Settings.OutPath, Description = "Select Output Folder" }; if (dlg.ShowDialog() == DialogResult.OK) { Settings.OutPath = dlg.SelectedPath; } }); #endregion //Populate Available Codecs, Audio and Video Sources ComboBoxes RefreshCommand.Execute(null); AudioViewModel.AudioSource.PropertyChanged += (Sender, Args) => { if (Args.PropertyName == nameof(AudioViewModel.AudioSource.SelectedRecordingSource) || Args.PropertyName == nameof(AudioViewModel.AudioSource.SelectedLoopbackSource)) { CheckFunctionalityAvailability(); } }; VideoViewModel.PropertyChanged += (Sender, Args) => { if (Args.PropertyName == nameof(VideoViewModel.SelectedVideoSource)) { CheckFunctionalityAvailability(); } }; _cursor = new MouseCursor(Settings.IncludeCursor); Settings.PropertyChanged += (Sender, Args) => { switch (Args.PropertyName) { case nameof(Settings.IncludeCursor): _cursor.Include = Settings.IncludeCursor; break; } }; // If Output Dircetory is not set. Set it to Documents\Captura\ if (string.IsNullOrWhiteSpace(Settings.OutPath)) { Settings.OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\"); } // Create the Output Directory if it does not exist if (!Directory.Exists(Settings.OutPath)) { Directory.CreateDirectory(Settings.OutPath); } HotKeyManager.RegisterAll(); SystemTrayManager.Init(); }
public static void Start() { m_recorder?.Reset(); m_recorder?.Start(); }