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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -29,11 +30,6 @@ namespace RedBookPlayer.GUI
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private Image[] _digits;
|
private Image[] _digits;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Timer for performing UI updates
|
|
||||||
/// </summary>
|
|
||||||
private Timer _updateTimer;
|
|
||||||
|
|
||||||
public PlayerView() => InitializeComponent(null);
|
public PlayerView() => InitializeComponent(null);
|
||||||
|
|
||||||
public PlayerView(string xaml) => InitializeComponent(xaml);
|
public PlayerView(string xaml) => InitializeComponent(xaml);
|
||||||
@@ -111,6 +107,7 @@ namespace RedBookPlayer.GUI
|
|||||||
private void InitializeComponent(string xaml)
|
private void InitializeComponent(string xaml)
|
||||||
{
|
{
|
||||||
DataContext = new PlayerViewModel();
|
DataContext = new PlayerViewModel();
|
||||||
|
PlayerViewModel.PropertyChanged += PlayerViewModelStateChanged;
|
||||||
|
|
||||||
// Load the theme
|
// Load the theme
|
||||||
try
|
try
|
||||||
@@ -126,23 +123,6 @@ namespace RedBookPlayer.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
InitializeDigits();
|
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>
|
/// <summary>
|
||||||
@@ -181,16 +161,16 @@ namespace RedBookPlayer.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the UI with the most recent information from the Player
|
/// Update the UI from the view-model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateView(object sender, ElapsedEventArgs e)
|
private void PlayerViewModelStateChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.InvokeAsync(() =>
|
Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
string digitString = PlayerViewModel.GenerateDigitString();
|
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]);
|
_digits[i].Source = GetBitmap(digitString[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ namespace RedBookPlayer.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the UI from the internal player
|
/// Update the view-model from the Player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void PlayerStateChanged(object sender, PropertyChangedEventArgs e)
|
private void PlayerStateChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -211,6 +211,10 @@ namespace RedBookPlayer.Hardware
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add event handling for the optical disc
|
||||||
|
if(_opticalDisc != null)
|
||||||
|
_opticalDisc.PropertyChanged += OpticalDiscStateChanged;
|
||||||
|
|
||||||
// Initialize the sound output
|
// Initialize the sound output
|
||||||
_soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);
|
_soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);
|
||||||
if(_soundOutput == null || !_soundOutput.Initialized)
|
if(_soundOutput == null || !_soundOutput.Initialized)
|
||||||
@@ -409,6 +413,11 @@ namespace RedBookPlayer.Hardware
|
|||||||
/// <param name="apply"></param>
|
/// <param name="apply"></param>
|
||||||
public void SetDeEmphasis(bool apply) => _soundOutput?.SetDeEmphasis(apply);
|
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>
|
/// <summary>
|
||||||
/// Update the player from the current SoundOutput
|
/// Update the player from the current SoundOutput
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user