Disconnect volume from Init

This commit is contained in:
Matt Nadareski
2021-10-08 23:16:02 -07:00
parent 27480a9e69
commit 09f9b2d775
3 changed files with 17 additions and 26 deletions

View File

@@ -398,6 +398,8 @@ namespace RedBookPlayer.GUI.ViewModels
// Initialize Player // Initialize Player
_player = new Player(App.Settings.NumberOfDiscs, App.Settings.Volume); _player = new Player(App.Settings.NumberOfDiscs, App.Settings.Volume);
_player.PropertyChanged += PlayerStateChanged;
PlayerStateChanged(this, null);
PlayerState = PlayerState.NoDisc; PlayerState = PlayerState.NoDisc;
} }
@@ -417,11 +419,8 @@ namespace RedBookPlayer.GUI.ViewModels
// Attempt to initialize Player // Attempt to initialize Player
_player.Init(path, playerOptions, opticalDiscOptions, autoPlay); _player.Init(path, playerOptions, opticalDiscOptions, autoPlay);
if(_player.Initialized) if(_player.Initialized)
{
_player.PropertyChanged += PlayerStateChanged;
PlayerStateChanged(this, null); PlayerStateChanged(this, null);
} }
}
#region Playback (UI) #region Playback (UI)

View File

@@ -66,22 +66,23 @@ namespace RedBookPlayer.Models.Audio
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
/// <param name="read">ReadFunction to use during decoding</param>
/// <param name="defaultVolume">Default volume between 0 and 100 to use when starting playback</param> /// <param name="defaultVolume">Default volume between 0 and 100 to use when starting playback</param>
public SoundOutput(int defaultVolume = 100) => Volume = defaultVolume; public SoundOutput(PlayerSource.ReadFunction read, int defaultVolume = 100)
{
Volume = defaultVolume;
SetupAudio(read);
}
/// <summary> /// <summary>
/// Initialize the output with a given image /// Initialize the output with a given image
/// </summary> /// </summary>
/// <param name="read">ReadFunction to use during decoding</param>
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param> /// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
public void Init(PlayerSource.ReadFunction read, bool autoPlay) public void Init(bool autoPlay)
{ {
// Reset initialization // Reset initialization
Initialized = false; Initialized = false;
// Setup the audio output
SetupAudio(read);
// Initialize playback, if necessary // Initialize playback, if necessary
if(autoPlay) if(autoPlay)
_soundOut.Play(); _soundOut.Play();
@@ -163,8 +164,6 @@ namespace RedBookPlayer.Models.Audio
/// </summary> /// </summary>
/// <param name="read">ReadFunction to use during decoding</param> /// <param name="read">ReadFunction to use during decoding</param>
private void SetupAudio(PlayerSource.ReadFunction read) private void SetupAudio(PlayerSource.ReadFunction read)
{
if(_source == null)
{ {
_source = new PlayerSource(read); _source = new PlayerSource(read);
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
@@ -172,11 +171,6 @@ namespace RedBookPlayer.Models.Audio
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) else if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
_soundOut = new Windows.AudioBackend(_source); _soundOut = new Windows.AudioBackend(_source);
} }
else
{
_soundOut.Stop();
}
}
#endregion #endregion
} }

View File

@@ -352,7 +352,8 @@ namespace RedBookPlayer.Models.Hardware
_currentDisc = 0; _currentDisc = 0;
_filterStage = new FilterStage(); _filterStage = new FilterStage();
_soundOutput = new SoundOutput(defaultVolume); _soundOutput = new SoundOutput(ProviderRead, defaultVolume);
_soundOutput.PropertyChanged += SoundOutputStateChanged;
_availableTrackList = 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++)
@@ -400,13 +401,10 @@ namespace RedBookPlayer.Models.Hardware
_filterStage.SetupFilters(); _filterStage.SetupFilters();
// Initialize the sound output // Initialize the sound output
_soundOutput.Init(ProviderRead, autoPlay); _soundOutput.Init(autoPlay);
if(_soundOutput == null || !_soundOutput.Initialized) if(_soundOutput == null || !_soundOutput.Initialized)
return; return;
// Add event handling for the sound output
_soundOutput.PropertyChanged += SoundOutputStateChanged;
// Load in the track list for the current disc // Load in the track list for the current disc
LoadTrackList(); LoadTrackList();