Implement shuffle (not surfaced)

This commit is contained in:
Matt Nadareski
2021-10-06 12:11:55 -07:00
parent b789b5cf47
commit 0854826583
4 changed files with 36 additions and 2 deletions

View File

@@ -100,6 +100,12 @@ namespace RedBookPlayer.GUI.ViewModels
PlayerView?.ViewModel?.ExecutePreviousTrack(); PlayerView?.ViewModel?.ExecutePreviousTrack();
} }
// Shuffle Track List
// else if(e.Key == App.Settings.ShuffleTracksKey)
// {
// PlayerView?.ViewModel?.ExecuteShuffle();
// }
// Next Index // Next Index
else if(e.Key == App.Settings.NextIndexKey) else if(e.Key == App.Settings.NextIndexKey)
{ {

View File

@@ -470,6 +470,11 @@ namespace RedBookPlayer.GUI.ViewModels
/// </summary> /// </summary>
public void ExecutePreviousTrack() => _player?.PreviousTrack(); public void ExecutePreviousTrack() => _player?.PreviousTrack();
/// <summary>
/// Shuffle the current track list
/// </summary>
public void ExecuteShuffle() => _player?.ShuffleTracks();
/// <summary> /// <summary>
/// Move to the next index /// Move to the next index
/// </summary> /// </summary>

View File

@@ -180,6 +180,11 @@ namespace RedBookPlayer.GUI.ViewModels
/// </summary> /// </summary>
public Key PreviousTrackKey { get; set; } = Key.Left; public Key PreviousTrackKey { get; set; } = Key.Left;
/// <summary>
/// Key assigned to shuffling the track list
/// </summary>
// public Key ShuffleTracksKey { get; set; } = Key.R;
/// <summary> /// <summary>
/// Key assigned to move to the next index /// Key assigned to move to the next index
/// </summary> /// </summary>

View File

@@ -415,7 +415,7 @@ namespace RedBookPlayer.Models.Hardware
} }
/// <summary> /// <summary>
/// Load the track list into the track dictionary for the current disc /// Load the track list into the track dictionary
/// </summary> /// </summary>
private void LoadTrackList() private void LoadTrackList()
{ {
@@ -455,6 +455,14 @@ namespace RedBookPlayer.Models.Hardware
} }
// Try to get back to the last loaded track // Try to get back to the last loaded track
SetTrackOrderIndex();
}
/// <summary>
/// Set the current track order index, if possible
/// </summary>
private void SetTrackOrderIndex()
{
int currentFoundTrack = 0; int currentFoundTrack = 0;
if(_trackPlaybackOrder == null || _trackPlaybackOrder.Count == 0) if(_trackPlaybackOrder == null || _trackPlaybackOrder.Count == 0)
{ {
@@ -553,6 +561,16 @@ namespace RedBookPlayer.Models.Hardware
} }
_trackPlaybackOrder = newPlaybackOrder; _trackPlaybackOrder = newPlaybackOrder;
switch(PlayerState)
{
case PlayerState.Stopped:
_currentTrackInOrder = 0;
break;
case PlayerState.Paused:
case PlayerState.Playing:
SetTrackOrderIndex();
break;
}
} }
/// <summary> /// <summary>
@@ -924,7 +942,7 @@ namespace RedBookPlayer.Models.Hardware
_opticalDiscs[CurrentDisc].LoadTrack(trackNumber); _opticalDiscs[CurrentDisc].LoadTrack(trackNumber);
} }
LoadTrackList(); SetTrackOrderIndex();
if(wasPlaying == PlayerState.Playing) if(wasPlaying == PlayerState.Playing)
Play(); Play();