Added playlist view and initial playlist view logic.
This commit is contained in:
55
Harmonia.UI/Caching/AudioBitmapCache.cs
Normal file
55
Harmonia.UI/Caching/AudioBitmapCache.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Avalonia.Media.Imaging;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Models;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Harmonia.UI.Caching;
|
||||
|
||||
public class AudioBitmapCache(IAudioImageExtractor audioImageExtractor) : MemoryCache<Song, Bitmap>, IAudioBitmapCache
|
||||
{
|
||||
protected override MemoryCacheOptions Options => new()
|
||||
{
|
||||
SizeLimit = 40,
|
||||
CompactionPercentage = 0.2,
|
||||
};
|
||||
|
||||
protected override TimeSpan SlidingExpiration => TimeSpan.FromSeconds(600);
|
||||
|
||||
protected override int MaxConcurrentRequests => 8;
|
||||
|
||||
protected override object? GetKey(Song key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key.ImageHash) == false)
|
||||
{
|
||||
return key.ImageHash;
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(key.ImageName) == false)
|
||||
{
|
||||
return key.ImageName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override async ValueTask<Bitmap?> FetchAsync(Song key, CancellationToken cancellationToken)
|
||||
{
|
||||
SongPictureInfo? songPictureInfo = await audioImageExtractor.ExtractImageAsync(key.FileName, cancellationToken);
|
||||
|
||||
if (songPictureInfo == null)
|
||||
return null;
|
||||
|
||||
using MemoryStream stream = new(songPictureInfo.Data);
|
||||
|
||||
return new Bitmap(stream);
|
||||
}
|
||||
|
||||
protected override long GetEntrySize(Bitmap entry)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
10
Harmonia.UI/Caching/IAudioBitmapCache.cs
Normal file
10
Harmonia.UI/Caching/IAudioBitmapCache.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Avalonia.Media.Imaging;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Models;
|
||||
|
||||
namespace Harmonia.UI.Caching;
|
||||
|
||||
public interface IAudioBitmapCache : ICache<Song, Bitmap>
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user