diff --git a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs index 2282ad1..87ffdec 100644 --- a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs +++ b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs @@ -398,6 +398,8 @@ namespace RedBookPlayer.GUI.ViewModels // Initialize Player _player = new Player(App.Settings.NumberOfDiscs, App.Settings.Volume); + _player.PropertyChanged += PlayerStateChanged; + PlayerStateChanged(this, null); PlayerState = PlayerState.NoDisc; } @@ -417,10 +419,7 @@ namespace RedBookPlayer.GUI.ViewModels // Attempt to initialize Player _player.Init(path, playerOptions, opticalDiscOptions, autoPlay); if(_player.Initialized) - { - _player.PropertyChanged += PlayerStateChanged; PlayerStateChanged(this, null); - } } #region Playback (UI) diff --git a/RedBookPlayer.Models/Audio/SoundOutput.cs b/RedBookPlayer.Models/Audio/SoundOutput.cs index 3decacc..4c526ae 100644 --- a/RedBookPlayer.Models/Audio/SoundOutput.cs +++ b/RedBookPlayer.Models/Audio/SoundOutput.cs @@ -66,22 +66,23 @@ namespace RedBookPlayer.Models.Audio /// /// Constructor /// + /// ReadFunction to use during decoding /// Default volume between 0 and 100 to use when starting playback - public SoundOutput(int defaultVolume = 100) => Volume = defaultVolume; + public SoundOutput(PlayerSource.ReadFunction read, int defaultVolume = 100) + { + Volume = defaultVolume; + SetupAudio(read); + } /// /// Initialize the output with a given image /// - /// ReadFunction to use during decoding /// True if playback should begin immediately, false otherwise - public void Init(PlayerSource.ReadFunction read, bool autoPlay) + public void Init(bool autoPlay) { // Reset initialization Initialized = false; - // Setup the audio output - SetupAudio(read); - // Initialize playback, if necessary if(autoPlay) _soundOut.Play(); @@ -164,18 +165,11 @@ namespace RedBookPlayer.Models.Audio /// ReadFunction to use during decoding private void SetupAudio(PlayerSource.ReadFunction read) { - if(_source == null) - { - _source = new PlayerSource(read); - if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - _soundOut = new Linux.AudioBackend(_source); - else if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - _soundOut = new Windows.AudioBackend(_source); - } - else - { - _soundOut.Stop(); - } + _source = new PlayerSource(read); + if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + _soundOut = new Linux.AudioBackend(_source); + else if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + _soundOut = new Windows.AudioBackend(_source); } #endregion diff --git a/RedBookPlayer.Models/Hardware/Player.cs b/RedBookPlayer.Models/Hardware/Player.cs index 7491fb2..cda02de 100644 --- a/RedBookPlayer.Models/Hardware/Player.cs +++ b/RedBookPlayer.Models/Hardware/Player.cs @@ -352,7 +352,8 @@ namespace RedBookPlayer.Models.Hardware _currentDisc = 0; _filterStage = new FilterStage(); - _soundOutput = new SoundOutput(defaultVolume); + _soundOutput = new SoundOutput(ProviderRead, defaultVolume); + _soundOutput.PropertyChanged += SoundOutputStateChanged; _availableTrackList = new Dictionary>(); for(int i = 0; i < _numberOfDiscs; i++) @@ -400,13 +401,10 @@ namespace RedBookPlayer.Models.Hardware _filterStage.SetupFilters(); // Initialize the sound output - _soundOutput.Init(ProviderRead, autoPlay); + _soundOutput.Init(autoPlay); if(_soundOutput == null || !_soundOutput.Initialized) return; - // Add event handling for the sound output - _soundOutput.PropertyChanged += SoundOutputStateChanged; - // Load in the track list for the current disc LoadTrackList();