private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { //On app start CurrentPlaying object is null so we must check for it before going further if (_currentPlaying == null) { return; } var index = Mp3Files.IndexOf(_currentPlaying); if (_player.playState == WMPPlayState.wmppsStopped) { if (index < Mp3Files.Count - 1) { Play(Mp3Files[index + 1]); //play next song when there is any and player stopped which happens only on media end, but because we can miss media end state we use this, which works fine } else { Play(Mp3Files[0]); } } //Progress bar and time progress updating var timeSpan = TimeSpan.FromSeconds(_player.controls.currentPosition); CurrentPositionTextBlock.Text = String.Format("{0}:{1:00}", timeSpan.Minutes, timeSpan.Seconds); ProgressBar.Value = _player.controls.currentPosition / _currentPlaying.MaxPosition * 100; }
private void PreviousButton_OnClick(object sender, RoutedEventArgs e) { if (_currentPlaying == null) { return; } var index = Mp3Files.IndexOf(_currentPlaying); if (index > 0) { Play(Mp3Files[index - 1]); } else { Play(Mp3Files[Mp3Files.Count - 1]); } }
private void NextButton_OnClick(object sender, RoutedEventArgs e) { if (_currentPlaying == null) { return; } var index = Mp3Files.IndexOf(_currentPlaying); if (index < Mp3Files.Count - 1) { Play(Mp3Files[index + 1]); } else { Play(Mp3Files[0]); } }