Adding initial playback bar logic.
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Models;
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.Core.Scanner;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -14,8 +18,8 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
private readonly IAudioImageCache _audioImageCache;
|
||||
private readonly DispatcherTimer _timer;
|
||||
|
||||
private bool _isPositionChangeInProgress;
|
||||
private CancellationTokenSource? _audioImageCancellationTokenSource;
|
||||
|
||||
private Song? _song;
|
||||
@@ -95,6 +99,17 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isPositionChangeInProgress;
|
||||
public bool IsPositionChangeInProgress
|
||||
{
|
||||
get { return _isPositionChangeInProgress; }
|
||||
set
|
||||
{
|
||||
_isPositionChangeInProgress = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRandom
|
||||
{
|
||||
get
|
||||
@@ -110,12 +125,14 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
|
||||
public string Greeting => "Welcome to Harmonia!";
|
||||
|
||||
public PlaybackBarViewModel(IAudioPlayer audioPlayer, IAudioImageCache audioImageCache)
|
||||
public PlaybackBarViewModel(IAudioPlayer audioPlayer, IAudioImageCache audioImageCache, IPlaylistRepository playlistRepository, IAudioFileScanner audioFileScanner)
|
||||
{
|
||||
_audioPlayer = audioPlayer;
|
||||
_audioPlayer.PlayingSongChanged += OnAudioPlayerPlayingSongChanged;
|
||||
|
||||
_audioImageCache = audioImageCache;
|
||||
|
||||
_timer = new(TimeSpan.FromMilliseconds(100), DispatcherPriority.Default, TickTock);
|
||||
}
|
||||
|
||||
private void OnAudioPlayerPlayingSongChanged(object? sender, EventArgs e)
|
||||
@@ -149,6 +166,16 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
SongImageSource = new(songPictureInfo.Stream);
|
||||
}
|
||||
|
||||
private void TickTock(object? sender, object e)
|
||||
{
|
||||
Position = _audioPlayer.Position;
|
||||
|
||||
if (IsPositionChangeInProgress)
|
||||
return;
|
||||
|
||||
CurrentPosition = _audioPlayer.Position;
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
_audioPlayer.Play();
|
||||
|
||||
Reference in New Issue
Block a user