Remove need for UI timer for updates

This commit is contained in:
Matt Nadareski
2021-07-04 23:43:55 -07:00
parent cd3ccbc8eb
commit 65ab29f29f
3 changed files with 16 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -29,11 +30,6 @@ namespace RedBookPlayer.GUI
/// </remarks>
private Image[] _digits;
/// <summary>
/// Timer for performing UI updates
/// </summary>
private Timer _updateTimer;
public PlayerView() => InitializeComponent(null);
public PlayerView(string xaml) => InitializeComponent(xaml);
@@ -111,6 +107,7 @@ namespace RedBookPlayer.GUI
private void InitializeComponent(string xaml)
{
DataContext = new PlayerViewModel();
PlayerViewModel.PropertyChanged += PlayerViewModelStateChanged;
// Load the theme
try
@@ -126,23 +123,6 @@ namespace RedBookPlayer.GUI
}
InitializeDigits();
_updateTimer = new Timer(1000 / 60);
_updateTimer.Elapsed += (sender, e) =>
{
try
{
UpdateView(sender, e);
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
};
_updateTimer.AutoReset = true;
_updateTimer.Start();
}
/// <summary>
@@ -181,9 +161,9 @@ namespace RedBookPlayer.GUI
}
/// <summary>
/// Update the UI with the most recent information from the Player
/// Update the UI from the view-model
/// </summary>
private void UpdateView(object sender, ElapsedEventArgs e)
private void PlayerViewModelStateChanged(object sender, PropertyChangedEventArgs e)
{
Dispatcher.UIThread.InvokeAsync(() =>
{

View File

@@ -305,7 +305,7 @@ namespace RedBookPlayer.GUI
}
/// <summary>
/// Update the UI from the internal player
/// Update the view-model from the Player
/// </summary>
private void PlayerStateChanged(object sender, PropertyChangedEventArgs e)
{

View File

@@ -211,6 +211,10 @@ namespace RedBookPlayer.Hardware
return;
}
// Add event handling for the optical disc
if(_opticalDisc != null)
_opticalDisc.PropertyChanged += OpticalDiscStateChanged;
// Initialize the sound output
_soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);
if(_soundOutput == null || !_soundOutput.Initialized)
@@ -409,6 +413,11 @@ namespace RedBookPlayer.Hardware
/// <param name="apply"></param>
public void SetDeEmphasis(bool apply) => _soundOutput?.SetDeEmphasis(apply);
/// <summary>
/// Update the player from the current OpticalDisc
/// </summary>
private void OpticalDiscStateChanged(object sender, PropertyChangedEventArgs e) => SetDiscInformation();
/// <summary>
/// Update the player from the current SoundOutput
/// </summary>