/// <summary> /// 上一曲 /// </summary> //private void SkipToPrevious() //{ // try // { // smtc.PlaybackStatus = MediaPlaybackStatus.Changing; // currentIndex--; // playbackList.MovePrevious(); // } // catch // { // } //} private void SkipToPrevious() { try { var index = (currentIndex - 1 + playlist.Count) % playlist.Count; PlayIndex(index); CurrentPlayItemChanged?.Invoke(playlist, new CurrentMediaPlayItemChangedEventArgs() { NewItem = playlist[index] }); } catch (Exception) { throw; } }
private void PlayIndex(int index) { if (index >= 0 && index <= playlist.Count) { smtc.PlaybackStatus = MediaPlaybackStatus.Changing; SetPlayItemSource(playlist[index]); BackgroundMediaPlayer.Current.Play(); smtc.PlaybackStatus = MediaPlaybackStatus.Playing; if (currentIndex != index) { currentIndex = index; CurrentPlayItemChanged?.Invoke(playlist, new CurrentMediaPlayItemChangedEventArgs() { NewItem = playlist[index] }); } } else { Debug.WriteLine("The song index is out of range"); } }