public DownloadingViewModel(IUnityContainer container) : base(container)
        {
            PauseAllCommand = new RelayCommand(() =>
            {
                foreach (var task in TransferTasks)
                {
                    if (PauseCommand.CanExecute(task))
                    {
                        PauseCommand.Execute(task);
                    }
                }
            },
                                               () => TransferTasks?.Any() ?? false);

            CancelAllCommand = new RelayCommand(() =>
            {
                foreach (var task in TransferTasks)
                {
                    if (CancelCommand.CanExecute(task))
                    {
                        CancelCommand.Execute(task);
                    }
                }
            },
                                                () => TransferTasks?.Any() ?? false);
        }
Beispiel #2
0
        /// <summary>
        /// Pauses this instance.
        /// </summary>
        public void Pause()
        {
            if (PauseCommand?.CanExecute(null) == true)
            {
                PauseCommand?.Execute(null);

                MediaState = MediaState == MediaState.Paused ? MediaState.Playing : MediaState.Paused;

                OnMediaStateChanged();
            }
        }
Beispiel #3
0
        public async Task Execute()
        {
            var log   = A.Fake <ILogger>();
            var radio = A.Fake <IRadio>();

            var command = new PauseCommand(log, radio);

            var result = await command.Execute(new string[0]);

            A.CallTo(() => radio.Pause()).MustHaveHappened();
            Assert.Equal(CommandResult.OK, result);
        }
Beispiel #4
0
        private void PauseButton_Checked(object sender, RoutedEventArgs e)
        {
            if (PauseCommand == null)
            {
                return;
            }

            var parameter = PauseCommandParameter ?? DataContext;

            if (PauseCommand.CanExecute(parameter))
            {
                PauseCommand.Execute(parameter);
            }
        }
 private void PlayPauseButton_Click(object sender, RoutedEventArgs e)
 {
     if (!MediaPlaying)
     {
         Play();
         if (PlayCommand != null && PlayCommand.CanExecute(EMPTY_PARAMETER))
         {
             PlayCommand.Execute(EMPTY_PARAMETER);
         }
     }
     else
     {
         Pause();
         if (PauseCommand != null && PauseCommand.CanExecute(EMPTY_PARAMETER))
         {
             PauseCommand.Execute(EMPTY_PARAMETER);
         }
     }
 }
Beispiel #6
0
        public DownloadingViewModel(IUnityContainer container) : base(container)
        {
            PauseAllCommand = new RelayCommand(() => TransferTasks.ForEach(item =>
            {
                if (PauseCommand.CanExecute(item))
                {
                    PauseCommand.Execute(item);
                }
            }),
                                               () => TransferTasks?.Any() ?? false);

            CancelAllCommand = new RelayCommand(() => TransferTasks.ForEach(item =>
            {
                if (CancelCommand.CanExecute(item))
                {
                    CancelCommand.Execute(item);
                }
            }),
                                                () => TransferTasks?.Any() ?? false);
        }
        /// <summary>
        /// Initializes the mouse events for the window.
        /// </summary>
        private void InitializeInputEvents()
        {
            #region Allow Keyboard Control

            var togglePlayPauseKeys = new[] { Key.Play, Key.MediaPlayPause, Key.Space };

            window.PreviewKeyDown += async(s, e) =>
            {
                // Console.WriteLine($"KEY: {e.Key}, SRC: {e.OriginalSource?.GetType().Name}");
                if (e.OriginalSource is TextBox)
                {
                    return;
                }

                // Keep the key focus on the main window
                FocusManager.SetIsFocusScope(this, true);
                FocusManager.SetFocusedElement(this, this);

                // Pause
                if (togglePlayPauseKeys.Contains(e.Key) && Media.IsPlaying)
                {
                    PauseCommand.Execute();
                    return;
                }

                // Play
                if (togglePlayPauseKeys.Contains(e.Key) && Media.IsPlaying == false)
                {
                    PlayCommand.Execute();
                    return;
                }

                // Seek to left
                if (e.Key == Key.Left)
                {
                    if (Media.IsPlaying)
                    {
                        await Media.Pause();
                    }
                    Media.Position -= Media.FrameStepDuration;
                }

                // Seek to right
                if (e.Key == Key.Right)
                {
                    if (Media.IsPlaying)
                    {
                        await Media.Pause();
                    }
                    Media.Position += Media.FrameStepDuration;
                }

                // Volume Up
                if (e.Key == Key.Add || e.Key == Key.VolumeUp)
                {
                    Media.Volume += 0.05;
                    return;
                }

                // Volume Down
                if (e.Key == Key.Subtract || e.Key == Key.VolumeDown)
                {
                    Media.Volume -= 0.05;
                    return;
                }

                // Mute/Unmute
                if (e.Key == Key.M || e.Key == Key.VolumeMute)
                {
                    Media.IsMuted = !Media.IsMuted;
                    return;
                }

                // Increase speed
                if (e.Key == Key.Up)
                {
                    Media.SpeedRatio += 0.05;
                    return;
                }

                // Decrease speed
                if (e.Key == Key.Down)
                {
                    Media.SpeedRatio -= 0.05;
                    return;
                }

                // Reset changes
                if (e.Key == Key.R)
                {
                    Media.SpeedRatio = 1.0;
                    Media.Volume     = 1.0;
                    Media.Balance    = 0;
                    Media.IsMuted    = false;
                }
            };

            #endregion

            #region Toggle Fullscreen with Double Click

            Media.PreviewMouseDoubleClick += (s, e) =>
            {
                if (s != Media)
                {
                    return;
                }
                e.Handled = true;
                ToggleFullscreenCommand.Execute();
            };

            #endregion

            #region Exit fullscreen with Escape key

            PreviewKeyDown += (s, e) =>
            {
                if (e.Key == Key.Escape && WindowStyle == WindowStyle.None)
                {
                    e.Handled = true;
                    ToggleFullscreenCommand.Execute();
                }
            };

            #endregion

            #region Handle Zooming with Mouse Wheel

            MouseWheel += (s, e) =>
            {
                if (Media.IsOpen == false || Media.IsOpening)
                {
                    return;
                }

                var delta = (e.Delta / 2000d).ToMultipleOf(0.05d);
                MediaZoom = Math.Round(MediaZoom + delta, 2);
            };

            UrlTextBox.PreviewMouseWheel += (s, e) =>
            {
                e.Handled = true;
            };

            #endregion

            #region Handle Play Pause with Mouse Clicks

            /*
             * Media.PreviewMouseDown += (s, e) =>
             * {
             *  if (s != Media) return;
             *  if (Media.IsOpen == false || Media.CanPause == false) return;
             *  if (Media.IsPlaying)
             *      PauseCommand.Execute();
             *  else
             *      PlayCommand.Execute();
             * };
             */

            #endregion

            #region Mouse Move Handling (Hide and Show Controls)

            LastMouseMoveTime = DateTime.UtcNow;

            MouseMove += (s, e) =>
            {
                var currentPosition = e.GetPosition(window);
                if (currentPosition.X != LastMousePosition.X || currentPosition.Y != LastMousePosition.Y)
                {
                    LastMouseMoveTime = DateTime.UtcNow;
                }

                LastMousePosition = currentPosition;
            };

            MouseLeave += (s, e) =>
            {
                LastMouseMoveTime = DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10));
            };

            var mouseMoveTimer = new DispatcherTimer(DispatcherPriority.Background)
            {
                Interval  = TimeSpan.FromMilliseconds(150),
                IsEnabled = true
            };

            mouseMoveTimer.Tick += (s, e) =>
            {
                var elapsedSinceMouseMove = DateTime.UtcNow.Subtract(LastMouseMoveTime);
                if (elapsedSinceMouseMove.TotalMilliseconds >= 3000 && Media.IsOpen && Controls.IsMouseOver == false &&
                    OpenMediaPopup.IsOpen == false && DebugWindowPopup.IsOpen == false && SoundMenuPopup.IsOpen == false)
                {
                    if (Controls.Opacity != 0d)
                    {
                        Cursor = System.Windows.Input.Cursors.None;
                        var sb = Player.FindResource("HideControlOpacity") as Storyboard;
                        Storyboard.SetTarget(sb, Controls);
                        sb.Begin();
                    }
                }
                else
                {
                    if (Controls.Opacity != 1d)
                    {
                        Cursor = System.Windows.Input.Cursors.Arrow;
                        var sb = Player.FindResource("ShowControlOpacity") as Storyboard;
                        Storyboard.SetTarget(sb, Controls);
                        sb.Begin();
                    }
                }
            };

            mouseMoveTimer.Start();

            #endregion
        }
Beispiel #8
0
 private void OnPauseClicked()
 {
     PauseClicked?.Invoke(this, EventArgs.Empty);
     PauseCommand?.Execute(null);
 }
 private void PlayButton_OnPauseClicked(object sender, EventArgs e)
 {
     PauseCommand?.Execute(null);
 }