コード例 #1
0
        async void StopRecording()
        {
            Status = "Stopped";

            var savingRecentItem = RecentViewModel.AddTemp(_currentFileName);

            RecorderState = RecorderState.NotRecording;

            CanChangeVideoSource = true;

            if (Settings.MinimizeOnStart)
            {
                WindowState = WindowState.Normal;
            }

            _timer.Stop();

            var rec = _recorder;

            _recorder = null;

            await Task.Run(() => rec.Dispose());

            // After Save
            RecentViewModel.RecentList.Remove(savingRecentItem);
            RecentViewModel.Add(_currentFileName, isVideo ? RecentItemType.Video : RecentItemType.Audio);

            SystemTrayManager.ShowNotification($"{(isVideo ? "Video" : "Audio")} Saved", Path.GetFileName(_currentFileName), 3000, () => Process.Start(_currentFileName));
        }
コード例 #2
0
        // Call before Exit to free Resources
        public void Dispose()
        {
            HotKeyManager.Dispose();
            SystemTrayManager.Dispose();

            AudioViewModel.Dispose();

            Settings.Save();
        }
コード例 #3
0
        public void SaveScreenShot(Bitmap bmp)
        {
            // Save to Disk or Clipboard
            if (bmp != null)
            {
                if (SelectedScreenShotSaveTo == "Clipboard")
                {
                    bmp.WriteToClipboard(SelectedScreenShotImageFormat.Equals(ImageFormat.Png));
                    Status = "Image Saved to Clipboard";
                }
                else // Save to Disk
                {
                    try
                    {
                        EnsureOutPath();

                        var extension = SelectedScreenShotImageFormat.Equals(ImageFormat.Icon) ? "ico"
                            : SelectedScreenShotImageFormat.Equals(ImageFormat.Jpeg) ? "jpg"
                            : SelectedScreenShotImageFormat.ToString().ToLower();

                        var fileName = Path.Combine(Settings.OutPath, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "." + extension);

                        bmp.Save(fileName, SelectedScreenShotImageFormat);
                        Status = "Image Saved to Disk";
                        RecentViewModel.Add(fileName, RecentItemType.Image);

                        SystemTrayManager.ShowNotification("ScreenShot Saved", Path.GetFileName(fileName), 3000, () => Process.Start(fileName));
                    }
                    catch (Exception E)
                    {
                        Status = "Not Saved. " + E.Message;
                    }
                }

                bmp.Dispose();
            }
            else
            {
                Status = "Not Saved - Image taken was Empty";
            }
        }
コード例 #4
0
        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();
        }