mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Add playback order (nw); fix eject
This commit is contained in:
@@ -298,9 +298,14 @@ namespace RedBookPlayer.Models.Hardware
|
|||||||
private OpticalDiscBase[] _opticalDiscs;
|
private OpticalDiscBase[] _opticalDiscs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of available tracks
|
/// List of available tracks organized by disc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Dictionary<int, List<int>> _trackList;
|
private Dictionary<int, List<int>> _availableTrackList;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Current track playback order
|
||||||
|
/// </summary>
|
||||||
|
private List<KeyValuePair<int, int>> _trackPlaybackOrder;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Last volume for mute toggling
|
/// Last volume for mute toggling
|
||||||
@@ -343,12 +348,14 @@ namespace RedBookPlayer.Models.Hardware
|
|||||||
_filterStage = new FilterStage();
|
_filterStage = new FilterStage();
|
||||||
_soundOutput = new SoundOutput(defaultVolume);
|
_soundOutput = new SoundOutput(defaultVolume);
|
||||||
|
|
||||||
_trackList = new Dictionary<int, List<int>>();
|
_availableTrackList = new Dictionary<int, List<int>>();
|
||||||
for(int i = 0; i < _numberOfDiscs; i++)
|
for(int i = 0; i < _numberOfDiscs; i++)
|
||||||
{
|
{
|
||||||
_trackList.Add(i, new List<int>());
|
_availableTrackList.Add(i, new List<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_trackPlaybackOrder = new List<KeyValuePair<int, int>>();
|
||||||
|
|
||||||
PropertyChanged += HandlePlaybackModes;
|
PropertyChanged += HandlePlaybackModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,10 +414,31 @@ namespace RedBookPlayer.Models.Hardware
|
|||||||
private void LoadTrackList()
|
private void LoadTrackList()
|
||||||
{
|
{
|
||||||
OpticalDiscBase opticalDisc = _opticalDiscs[CurrentDisc];
|
OpticalDiscBase opticalDisc = _opticalDiscs[CurrentDisc];
|
||||||
|
|
||||||
|
// If the disc exists, add it to the dictionary
|
||||||
|
if(_opticalDiscs[CurrentDisc] != null)
|
||||||
|
{
|
||||||
if (opticalDisc is CompactDisc compactDisc)
|
if (opticalDisc is CompactDisc compactDisc)
|
||||||
_trackList[CurrentDisc] = compactDisc.Tracks.Select(t => (int)t.TrackSequence).OrderBy(s => s).ToList();
|
_availableTrackList[CurrentDisc] = compactDisc.Tracks.Select(t => (int)t.TrackSequence).OrderBy(s => s).ToList();
|
||||||
else
|
else
|
||||||
_trackList[CurrentDisc] = Enumerable.Range(1, opticalDisc.TotalTracks).ToList();
|
_availableTrackList[CurrentDisc] = Enumerable.Range(1, opticalDisc.TotalTracks).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the disc is null, then make sure it's removed
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_availableTrackList[CurrentDisc] = new List<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through the dictionary and repopulate the playback order
|
||||||
|
for(int i = 0; i < _numberOfDiscs; i++)
|
||||||
|
{
|
||||||
|
if(_availableTrackList[i] == null || _availableTrackList[i].Count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<int> availableTracks = _availableTrackList[i];
|
||||||
|
_trackPlaybackOrder.AddRange(availableTracks.Select(t => new KeyValuePair<int, int>(i, t)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Playback (UI)
|
#region Playback (UI)
|
||||||
@@ -498,11 +526,21 @@ namespace RedBookPlayer.Models.Hardware
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
_soundOutput.Eject();
|
|
||||||
_opticalDiscs[CurrentDisc] = null;
|
_opticalDiscs[CurrentDisc] = null;
|
||||||
|
LoadTrackList();
|
||||||
|
|
||||||
|
// Only de-initialize the player if all discs are ejected
|
||||||
|
if(_opticalDiscs.All(d => d == null || !d.Initialized))
|
||||||
|
{
|
||||||
|
_soundOutput.Eject();
|
||||||
PlayerState = PlayerState.NoDisc;
|
PlayerState = PlayerState.NoDisc;
|
||||||
Initialized = false;
|
Initialized = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlayerState = PlayerState.Stopped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Move to the next disc
|
/// Move to the next disc
|
||||||
|
|||||||
Reference in New Issue
Block a user