mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Remove need for UI timer for updates
This commit is contained in:
@@ -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,16 +161,16 @@ 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(() =>
|
||||
{
|
||||
string digitString = PlayerViewModel.GenerateDigitString();
|
||||
for (int i = 0; i < _digits.Length; i++)
|
||||
for(int i = 0; i < _digits.Length; i++)
|
||||
{
|
||||
if (_digits[i] != null)
|
||||
if(_digits[i] != null)
|
||||
_digits[i].Source = GetBitmap(digitString[i]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user