Various updates.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Engine;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Models;
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
@@ -8,10 +10,10 @@ using Harmonia.WinUI.Caching;
|
||||
using Harmonia.WinUI.Storage;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -20,7 +22,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Input;
|
||||
using Windows.ApplicationModel.Contacts;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
|
||||
using Timer = System.Timers.Timer;
|
||||
@@ -30,6 +31,7 @@ namespace Harmonia.WinUI.ViewModels;
|
||||
public partial class PlaylistViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
private readonly IAudioImageCache _audioImageCache;
|
||||
private readonly IAudioBitmapImageCache _audioBitmapImageCache;
|
||||
private readonly IAudioFileScanner _audioFileScanner;
|
||||
private readonly IAudioEngine _audioEngine;
|
||||
@@ -126,6 +128,7 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
|
||||
public PlaylistViewModel(
|
||||
IAudioPlayer audioPlayer,
|
||||
IAudioImageCache audioImageCache,
|
||||
IAudioBitmapImageCache audioBitmapImageCache,
|
||||
IAudioFileScanner audioFileScanner,
|
||||
IAudioEngine audioEngine,
|
||||
@@ -136,16 +139,27 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
_audioPlayer.PlaylistChanged += OnPlaylistChanged;
|
||||
_audioPlayer.PlayingSongChanged += OnPlayingSongChanged;
|
||||
|
||||
_audioImageCache = audioImageCache;
|
||||
_audioBitmapImageCache = audioBitmapImageCache;
|
||||
_audioFileScanner = audioFileScanner;
|
||||
_audioEngine = audioEngine;
|
||||
_storageProvider = storageProvider;
|
||||
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
|
||||
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
|
||||
|
||||
// Testing
|
||||
Task.Run(() => PlayDemoSong(playlistRepository));
|
||||
}
|
||||
|
||||
private void OnFilteredPlaylistSongsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (IsUserUpdating == false)
|
||||
return;
|
||||
|
||||
int x = 1;
|
||||
}
|
||||
|
||||
private async Task PlayDemoSong(IPlaylistRepository playlistRepository)
|
||||
{
|
||||
if (playlistRepository.Get().Count == 0)
|
||||
@@ -238,13 +252,24 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
await _audioPlayer.LoadAsync(playlistSong, PlaybackMode.LoadAndPlay);
|
||||
}
|
||||
|
||||
public async Task<SongPictureInfo?> GetSongPictureInfoAsync(int hashCode, PlaylistSong playlistSong)
|
||||
{
|
||||
_imageCancellationTokens.TryGetValue(hashCode, out CancellationTokenSource? cancellationTokenSource);
|
||||
cancellationTokenSource?.Cancel();
|
||||
|
||||
cancellationTokenSource = new();
|
||||
_imageCancellationTokens.AddOrUpdate(hashCode, cancellationTokenSource, (_, _) => cancellationTokenSource);
|
||||
|
||||
return await _audioImageCache.GetAsync(playlistSong.Song, cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
public async Task<BitmapImage?> GetBitmapImageAsync(int hashCode, PlaylistSong playlistSong)
|
||||
{
|
||||
_imageCancellationTokens.TryGetValue(hashCode, out CancellationTokenSource? cancellationTokenSource);
|
||||
cancellationTokenSource?.Cancel();
|
||||
|
||||
cancellationTokenSource = new();
|
||||
_imageCancellationTokens.AddOrUpdate(hashCode, cancellationTokenSource, (_,_) => cancellationTokenSource);
|
||||
_imageCancellationTokens.AddOrUpdate(hashCode, cancellationTokenSource, (_, _) => cancellationTokenSource);
|
||||
|
||||
return await _audioBitmapImageCache.GetAsync(playlistSong.Song, cancellationTokenSource.Token);
|
||||
}
|
||||
@@ -290,7 +315,7 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
List<PlaylistSong> filteredPlaylistSongs = [.. Playlist.Songs.Where(playlistSong => IsFiltered(playlistSong.Song))];
|
||||
//FilteredPlaylistSongs = [.. filteredPlaylistSongs];
|
||||
|
||||
for (int i = FilteredPlaylistSongs.Count -1; i >= 0; i--)
|
||||
for (int i = FilteredPlaylistSongs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
PlaylistSong playlistSong = FilteredPlaylistSongs[i];
|
||||
|
||||
@@ -382,7 +407,7 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
|
||||
private FilePickerFileType GetAudioFileTypes()
|
||||
{
|
||||
string[] patterns = _audioEngine.SupportedFormats.Select(format => format.Replace("*", "")).ToArray();
|
||||
string[] patterns = [.. _audioEngine.SupportedFormats.Select(format => format.Replace("*", ""))];
|
||||
|
||||
return new()
|
||||
{
|
||||
@@ -396,7 +421,7 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
if (Playlist == null)
|
||||
return;
|
||||
|
||||
string? path = await _storageProvider.GetPathAsync();
|
||||
string? path = await _storageProvider.GetPathAsync();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return;
|
||||
@@ -448,7 +473,7 @@ public partial class PlaylistViewModel : ViewModelBase
|
||||
{
|
||||
if (SelectedPlaylistSongs.Count == 0)
|
||||
return;
|
||||
|
||||
|
||||
CopySelectedSongsToClipboard();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user