From 9a787270a20f4d67671c86eb81852a4acca967d7 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 3 Jul 2021 21:15:23 -0700 Subject: [PATCH] Fix stopping playback --- RedBookPlayer/GUI/PlayerView.xaml.cs | 13 ------- RedBookPlayer/GUI/PlayerViewModel.cs | 55 +++++++++++++++------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/RedBookPlayer/GUI/PlayerView.xaml.cs b/RedBookPlayer/GUI/PlayerView.xaml.cs index 149225e..7dabeae 100644 --- a/RedBookPlayer/GUI/PlayerView.xaml.cs +++ b/RedBookPlayer/GUI/PlayerView.xaml.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -112,7 +111,6 @@ namespace RedBookPlayer.GUI private void InitializeComponent(string xaml) { DataContext = new PlayerViewModel(); - PlayerViewModel.PropertyChanged += UpdateModel; // Load the theme try @@ -182,17 +180,6 @@ namespace RedBookPlayer.GUI }; } - /// - /// Update the Player with the most recent information from the UI - /// - private void UpdateModel(object sender, PropertyChangedEventArgs e) - { - Dispatcher.UIThread.InvokeAsync(() => - { - PlayerViewModel.UpdateModel(); - }); - } - /// /// Update the UI with the most recent information from the Player /// diff --git a/RedBookPlayer/GUI/PlayerViewModel.cs b/RedBookPlayer/GUI/PlayerViewModel.cs index 8a47f7b..4030ba5 100644 --- a/RedBookPlayer/GUI/PlayerViewModel.cs +++ b/RedBookPlayer/GUI/PlayerViewModel.cs @@ -20,27 +20,48 @@ namespace RedBookPlayer.GUI #region Player Status + /// + /// Indicate if the model is ready to be used + /// public bool Initialized => _player?.Initialized ?? false; - private bool? _playing; + /// + /// Indicate the player state + /// public bool? Playing { - get => _playing; - set => this.RaiseAndSetIfChanged(ref _playing, value); + get => _player?.Playing ?? false; + set + { + if(_player != null) + _player.Playing = value; + } } - private int _volume; + /// + /// Indicate the current playback volume + /// public int Volume { - get => _volume; - set => this.RaiseAndSetIfChanged(ref _volume, value); + get => _player?.Volume ?? 100; + set + { + if(_player != null) + _player.Volume = value; + } } - private bool _applyDeEmphasis; + /// + /// Indicates if de-emphasis should be applied + /// public bool ApplyDeEmphasis { - get => _applyDeEmphasis; - set => this.RaiseAndSetIfChanged(ref _applyDeEmphasis, value); + get => _player?.ApplyDeEmphasis ?? false; + set + { + if(_player != null) + _player.ApplyDeEmphasis = value; + } } #endregion @@ -223,12 +244,9 @@ namespace RedBookPlayer.GUI if(_player?.Initialized != true) return; - Playing = _player.Playing; CurrentSector = _player.GetCurrentSectorTime(); TotalSectors = _player.OpticalDisc.TotalTime; - Volume = _player.Volume; - ApplyDeEmphasis = _player.ApplyDeEmphasis; HiddenTrack = _player.OpticalDisc.TimeOffset > 150; if(_player.OpticalDisc is CompactDisc compactDisc) @@ -247,19 +265,6 @@ namespace RedBookPlayer.GUI } } - /// - /// Update the internal player from the UI - /// - public void UpdateModel() - { - if(_player?.Initialized != true) - return; - - _player.Playing = Playing; - _player.Volume = Volume; - _player.ApplyDeEmphasis = ApplyDeEmphasis; - } - #endregion } } \ No newline at end of file