Updated SongPictureInfo use to async copy of picture data stream. Update other classes accordingly.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Models;
|
||||
@@ -8,9 +9,11 @@ using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.Core.Scanner;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Harmonia.UI.ViewModels;
|
||||
|
||||
@@ -33,6 +36,7 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
{
|
||||
_song = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(FormattedSongInfo));
|
||||
|
||||
CurrentPosition = 0; // What if player is being loaded and returning to save state?
|
||||
Position = 0;
|
||||
@@ -54,6 +58,10 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public string FormattedSongInfo => Song != null
|
||||
? $"{Song.FileType} - {Song.BitRate} kbps - {Song.SampleRate} Hz"
|
||||
: string.Empty;
|
||||
|
||||
private double _currentPosition;
|
||||
public double CurrentPosition
|
||||
{
|
||||
@@ -123,7 +131,11 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public string Greeting => "Welcome to Harmonia!";
|
||||
public ICommand PlaySongCommand => new RelayCommand(Play);
|
||||
public ICommand PauseSongCommand => new RelayCommand(Pause);
|
||||
public ICommand StopSongCommand => new RelayCommand(Stop);
|
||||
public ICommand PreviousSongCommand => new RelayCommand(Previous);
|
||||
public ICommand NextSongCommand => new RelayCommand(Next);
|
||||
|
||||
public PlaybackBarViewModel(IAudioPlayer audioPlayer, IAudioImageCache audioImageCache, IPlaylistRepository playlistRepository, IAudioFileScanner audioFileScanner)
|
||||
{
|
||||
@@ -133,6 +145,27 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
_audioImageCache = audioImageCache;
|
||||
|
||||
_timer = new(TimeSpan.FromMilliseconds(100), DispatcherPriority.Default, TickTock);
|
||||
|
||||
PlayDemoSong(playlistRepository, audioFileScanner);
|
||||
}
|
||||
|
||||
private async Task PlayDemoSong(IPlaylistRepository playlistRepository, IAudioFileScanner audioFileScanner, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (playlistRepository.Get().Count == 0)
|
||||
{
|
||||
playlistRepository.AddPlaylist();
|
||||
|
||||
Playlist playlist = playlistRepository.Get().First();
|
||||
|
||||
//string songPath = @"D:\Music\Game Music\Bobby Prince\Doom II";
|
||||
//string songPath = @"D:\Music\Anime Music\HimeHina";
|
||||
string songPath = @"D:\Music\K-Pop";
|
||||
|
||||
Song[] songs = await audioFileScanner.GetSongsFromPathAsync(songPath, cancellationToken);
|
||||
playlist.AddSongs(songs);
|
||||
}
|
||||
|
||||
await _audioPlayer.LoadAsync(playlistRepository.Get().First().Songs[0], PlaybackMode.LoadAndPlay);
|
||||
}
|
||||
|
||||
private void OnAudioPlayerPlayingSongChanged(object? sender, EventArgs e)
|
||||
@@ -163,7 +196,11 @@ public partial class PlaybackBarViewModel : ViewModelBase
|
||||
|
||||
private void SetSongImageSource(SongPictureInfo songPictureInfo)
|
||||
{
|
||||
SongImageSource = new(songPictureInfo.Stream);
|
||||
if (songPictureInfo.Data.Length == 0)
|
||||
return;
|
||||
|
||||
using MemoryStream stream = new(songPictureInfo.Data);
|
||||
SongImageSource = new(stream);
|
||||
}
|
||||
|
||||
private void TickTock(object? sender, object e)
|
||||
|
||||
Reference in New Issue
Block a user