Various updates.
This commit is contained in:
@@ -12,6 +12,8 @@ using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.System;
|
||||
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
|
||||
|
||||
namespace Harmonia.WinUI.ViewModels;
|
||||
|
||||
@@ -20,6 +22,7 @@ public partial class PlayerViewModel : ViewModelBase
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
private readonly IAudioBitmapImageCache _audioBitmapImageCache;
|
||||
private readonly DispatcherTimer _timer;
|
||||
private readonly DispatcherQueue _dispatcherQueue;
|
||||
|
||||
private CancellationTokenSource? _songImageCancellationTokenSource;
|
||||
|
||||
@@ -185,6 +188,18 @@ public partial class PlayerViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanUpdatePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return _audioPlayer.State != AudioPlaybackState.Stopped;
|
||||
}
|
||||
private set
|
||||
{
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand PlaySongCommand => new RelayCommand(Play);
|
||||
public ICommand PauseSongCommand => new RelayCommand(Pause);
|
||||
public ICommand StopSongCommand => new RelayCommand(Stop);
|
||||
@@ -208,6 +223,8 @@ public partial class PlayerViewModel : ViewModelBase
|
||||
};
|
||||
|
||||
_timer.Tick += TickTock;
|
||||
|
||||
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
@@ -230,9 +247,13 @@ public partial class PlayerViewModel : ViewModelBase
|
||||
_songImageCancellationTokenSource = new();
|
||||
CancellationToken cancellationToken = _songImageCancellationTokenSource.Token;
|
||||
|
||||
BitmapImage? bitmapImage = await _audioBitmapImageCache.GetAsync(Song, cancellationToken);
|
||||
//BitmapImage? bitmapImage = await _audioBitmapImageCache.GetAsync(Song, cancellationToken);
|
||||
|
||||
DispatcherQueue.GetForCurrentThread().TryEnqueue(() => SongImageSource = bitmapImage);
|
||||
_dispatcherQueue.TryEnqueue(async () =>
|
||||
{
|
||||
BitmapImage? bitmapImage = await _audioBitmapImageCache.GetAsync(Song, cancellationToken);
|
||||
SongImageSource = bitmapImage;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnAudioPlayerPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
@@ -241,6 +262,7 @@ public partial class PlayerViewModel : ViewModelBase
|
||||
{
|
||||
case nameof(_audioPlayer.State):
|
||||
UpdateTimer();
|
||||
OnPropertyChanged(nameof(CanUpdatePosition));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user