private void OnPlayPauseButtonClicked(object sender, ManipulationCompletedEventArgs args) { if (MediaPlayerElement.CurrentState == MediaElementState.Playing) { MediaPlayerElement.Pause(); } else { MediaPlayerElement.Play(); } }
private void OnMediaOpened(object sender, RoutedEventArgs e) { MediaProgressBar.Maximum = (int)MediaPlayerElement.NaturalDuration.TimeSpan.TotalMilliseconds; ProgressUpdateTimer.Stop(); MediaControlPanel.Visibility = Visibility.Visible; if (AutostartOnMediaLoad) { AutostartOnMediaLoad = false; MediaPlayerElement.Play(); } else // Workaround: for issue with video beeing reset on page forward/back navigation { MediaPlayerElement.Pause(); // To enable changing position GoToPosition(CurrentPositionMiliseconds); UpdateTrackTimeDisplay(); } }
private void SetUpEventsHandler() { _mediaPlayerViewModel.PropertyChanged += (sender, e) => { PlayMethodView(); }; _mediaPlayerViewModel.PlayValueRequested += (sender, e) => { PlayMethodView(); }; _mediaPlayerViewModel.VolumeDownEvent += (sender, e) => { if (MediaPlayerElement.Volume > 0) { MediaPlayerElement.Volume -= 0.1; } }; _mediaPlayerViewModel.VolumeUpEvent += (sender, e) => { if (MediaPlayerElement.Volume < 1) { MediaPlayerElement.Volume += 0.1; } }; _mediaPlayerViewModel.SpeedRatioUpEvent += (sender, e) => { MediaPlayerElement.SpeedRatio += 0.25; MessageBox.Show(MediaPlayerElement.SpeedRatio.ToString(), "Speed Ratio"); }; _mediaPlayerViewModel.SpeedRatioDownEvent += (sender, e) => { MediaPlayerElement.SpeedRatio -= 0.15; MessageBox.Show(MediaPlayerElement.SpeedRatio.ToString(), "Speed Ratio"); }; _mediaPlayerViewModel.MoveForwardRequested += (sender, e) => { if (PlayListView.SelectedIndex < PlayListView.Items.Count && PlayListView.Items.Count > 0) { PlayListView.SelectedIndex = (PlayListView.SelectedIndex + 1) % PlayListView.Items.Count;; _mediaPlayerViewModel.OnItemSelectedInPlayListCommand.Execute(PlayListView.SelectedValue); } }; _mediaPlayerViewModel.MoveBackwardRequested += (sender, e) => { if (PlayListView.SelectedIndex < PlayListView.Items.Count && PlayListView.Items.Count > 0) { PlayListView.SelectedIndex = (PlayListView.SelectedIndex - 1 + PlayListView.Items.Count) % PlayListView.Items.Count; _mediaPlayerViewModel.OnItemSelectedInPlayListCommand.Execute(PlayListView.SelectedValue); } }; _mediaPlayerViewModel.PauseRequested += (sender, e) => { if (PlayButton.Content == FindResource("PauseImage")) { MediaPlayerElement.Pause(); PlayButton.Content = FindResource("PlayImage"); // this.PlayButton.IsChecked = true; } }; _mediaPlayerViewModel.FullScreenEvent += (sender, e) => { if (WindowStyle != WindowStyle.None) { // this.Visibility = Visibility.Collapsed; WindowStyle = WindowStyle.None; Taskbar.Visibility = Visibility.Collapsed; MovieSliderBar.Visibility = Visibility.Collapsed; MenuBar.Visibility = Visibility.Collapsed; PlayListView.Visibility = Visibility.Collapsed; MediaPlayerElement.Stretch = Stretch.Fill; ResizeMode = ResizeMode.NoResize; WindowState = WindowState.Maximized; Visibility = Visibility.Visible; } else { WindowStyle = WindowStyle.SingleBorderWindow; WindowState = WindowState.Maximized; Taskbar.Visibility = Visibility.Visible; MovieSliderBar.Visibility = Visibility.Visible; MenuBar.Visibility = Visibility.Visible; PlayListView.Visibility = Visibility.Visible; MediaPlayerElement.Stretch = Stretch.None; ResizeMode = ResizeMode.CanResize; } }; _mediaPlayerViewModel.StopRequested += (sender, e) => { MediaPlayerElement.Position = new TimeSpan(0, 0, 0); MediaPlayerElement.Stop(); MoviePositionSlider.Value = 0; PlayButton.IsChecked = true; PlayButton.Content = FindResource("PlayImage"); }; _mediaPlayerViewModel.MediaOpenedRequested += (sender, e) => { if (MediaPlayerElement.IsLoaded) { // Create a timer that will update the counters and the time slider timerVideoTime = new DispatcherTimer(); timerVideoTime.Interval = new TimeSpan(0, 0, 1); timerVideoTime.Tick += Timer_Tick; timerVideoTime.Start(); } }; _mediaPlayerViewModel.ChangeBackgroundEvent += (sender, e) => { Background = Background = new ImageBrush(new BitmapImage(new Uri(_mediaPlayerViewModel.ImageUri))); }; }