Inheritance: ViewModelBase
Exemplo n.º 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));
        }
Exemplo n.º 2
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";
            }
        }
        void StartRecording()
        {
            var duration = OthersViewModel.Duration;
            var delay    = OthersViewModel.StartDelay;

            if (duration != 0 && (delay * 1000 > duration))
            {
                Status = "Delay cannot be greater than Duration";
                SystemSounds.Asterisk.Play();
                return;
            }

            if (OthersViewModel.MinimizeOnStart)
            {
                WindowState = WindowState.Minimized;
            }

            ReadyToRecord = false;

            var noVideo = VideoViewModel.SelectedVideoSourceKind == VideoSourceKind.NoVideo;

            var extension = noVideo
                            //? (AudioViewModel.Encode && AudioViewModel.SelectedAudioSource is WaveInDevice ? ".mp3" : ".wav")
                ? ".wav"
                : (VideoViewModel.SelectedCodec.Name == "Gif" ? ".gif" : ".avi");

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

            Status = delay > 0 ? $"Recording from t = {delay} ms..." : "Recording...";

            _timer.Stop();
            TimeSpan = TimeSpan.Zero;

            var audioSource = AudioViewModel.GetAudioSource();

            var imgProvider = GetImageProvider();

            var videoEncoder = GetVideoFileWriter(imgProvider);

            if (_recorder == null)
            {
                if (noVideo)
                {
                    _recorder = new AudioRecorder(audioSource, AudioViewModel.GetAudioFileWriter(_currentFileName, audioSource.WaveFormat));
                }

                else
                {
                    _recorder = new Recorder(videoEncoder, imgProvider, VideoViewModel.FrameRate, audioSource);
                }
            }

            _recorder.RecordingStopped += (s, E) =>
            {
                OnStopped();

                if (E?.Error == null)
                {
                    return;
                }

                Status = "Error";
                MessageBox.Show(E.ToString());
            };

            RecentViewModel.Add(_currentFileName, videoEncoder == null ? RecentItemType.Audio : RecentItemType.Video);

            _recorder.Start(delay);

            _timer.Start();
        }
        void CaptureScreenShot()
        {
            if (!Directory.Exists(OutPath))
            {
                Directory.CreateDirectory(OutPath);
            }

            string fileName = null;

            var imgFmt = ScreenShotViewModel.SelectedImageFormat;

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

            var saveToClipboard = ScreenShotViewModel.SelectedSaveTo == "Clipboard";

            if (!saveToClipboard)
            {
                fileName = Path.Combine(OutPath,
                                        DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "." + extension);
            }

            Bitmap bmp = null;

            var selectedVideoSource = VideoViewModel.SelectedVideoSource;
            var includeCursor       = OthersViewModel.Cursor;

            switch (VideoViewModel.SelectedVideoSourceKind)
            {
            case VideoSourceKind.Window:
                var hWnd = (selectedVideoSource as WindowVSLI)?.Window ?? Window.DesktopWindow;

                if (hWnd == Window.DesktopWindow)
                {
                    bmp = ScreenShot.Capture(includeCursor);
                }
                else if (hWnd == RegionSelector.Instance.Window)
                {
                    bmp = ScreenShot.Capture(RegionSelector.Instance.Rectangle, includeCursor);
                }
                else
                {
                    bmp = ScreenShot.CaptureTransparent(hWnd, includeCursor,
                                                        ScreenShotViewModel.DoResize, ScreenShotViewModel.ResizeWidth, ScreenShotViewModel.ResizeHeight);
                }
                break;

            case VideoSourceKind.Screen:
                bmp = (selectedVideoSource as ScreenVSLI)?.Capture(includeCursor);
                break;
            }

            // Save to Disk or Clipboard
            if (bmp != null)
            {
                if (saveToClipboard)
                {
                    bmp.WriteToClipboard(imgFmt.Equals(ImageFormat.Png));
                    Status = "Image Saved to Clipboard";
                }
                else
                {
                    try
                    {
                        bmp.Save(fileName, imgFmt);
                        Status = "Image Saved to Disk";
                        RecentViewModel.Add(fileName, RecentItemType.Image);
                    }
                    catch (Exception E)
                    {
                        Status = "Not Saved. " + E.Message;
                    }
                }
            }
            else
            {
                Status = "Not Saved - Image taken was Empty";
            }
        }