Implemented tag refresh on a playlist. Made audio file scanning truly asynchronous. Added basic playlist sorting functionality.
This commit is contained in:
@@ -164,6 +164,8 @@ public class Playlist
|
||||
|
||||
public void ImportTags(Song[] songs)
|
||||
{
|
||||
List<PlaylistSong> updatedPlaylistSongs = [];
|
||||
|
||||
foreach (Song song in songs)
|
||||
{
|
||||
PlaylistSong[] playlistSongs = [.. Songs.Where(playlistSong =>
|
||||
@@ -171,10 +173,24 @@ public class Playlist
|
||||
|
||||
foreach (PlaylistSong playlistSong in playlistSongs)
|
||||
{
|
||||
//playlistSong.Song = song;
|
||||
//playlistSong.Song.Update(song);
|
||||
playlistSong.Song.Update(song);
|
||||
}
|
||||
|
||||
updatedPlaylistSongs.AddRange(playlistSongs);
|
||||
}
|
||||
|
||||
if (updatedPlaylistSongs.Count == 0)
|
||||
return;
|
||||
|
||||
PlaylistUpdatedEventArgs eventArgs = new()
|
||||
{
|
||||
Action = PlaylistUpdateAction.Refresh,
|
||||
Index = -1,
|
||||
Count = updatedPlaylistSongs.Count,
|
||||
Songs = [.. updatedPlaylistSongs]
|
||||
};
|
||||
|
||||
PlaylistUpdated?.Invoke(this, eventArgs);
|
||||
}
|
||||
|
||||
public void RemoveMissingSongs()
|
||||
|
||||
@@ -17,5 +17,9 @@ public enum PlaylistUpdateAction
|
||||
/// <summary>
|
||||
/// The contents of the collection changed dramatically.
|
||||
/// </summary>
|
||||
Reset
|
||||
Reset,
|
||||
/// <summary>
|
||||
/// The tags of the songs in the collection were refreshed.
|
||||
/// </summary>
|
||||
Refresh
|
||||
}
|
||||
@@ -9,22 +9,19 @@ public class AudioFileScanner(IAudioEngine audioEngine, ITagResolver tagResolver
|
||||
{
|
||||
public async Task<Song[]> GetSongsAsync(string[] fileNames, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Song> songs = [];
|
||||
Song?[] songs = new Song?[fileNames.Length];
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
await Parallel.ForEachAsync(Enumerable.Range(0, fileNames.Length), cancellationToken, async (index, token) =>
|
||||
{
|
||||
string fileName = fileNames[index];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fileName) || File.Exists(fileName) == false)
|
||||
continue;
|
||||
return;
|
||||
|
||||
Song? song = await GetSongAsync(fileName, cancellationToken);
|
||||
songs[index] = await GetSongAsync(fileName, token);
|
||||
});
|
||||
|
||||
if (song == null)
|
||||
continue;
|
||||
|
||||
songs.Add(song);
|
||||
}
|
||||
|
||||
return [.. songs];
|
||||
return [.. songs.Where(song => song != null)!];
|
||||
}
|
||||
|
||||
private async Task<Song> GetSongAsync(string fileName, CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user