Various updates.
This commit is contained in:
@@ -12,8 +12,6 @@ namespace Harmonia.WinUI.Caching;
|
||||
|
||||
public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : MemoryCache<Song, BitmapImage>, IAudioBitmapImageCache
|
||||
{
|
||||
protected virtual int MaxImageWidthOrHeight => 1000;
|
||||
|
||||
protected override MemoryCacheOptions Options => new()
|
||||
{
|
||||
SizeLimit = 200_000_000,
|
||||
@@ -21,8 +19,8 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
||||
};
|
||||
|
||||
protected override TimeSpan SlidingExpiration => TimeSpan.FromSeconds(600);
|
||||
|
||||
protected override int MaxConcurrentRequests => 8;
|
||||
protected virtual int MaxImageWidthOrHeight => 1000;
|
||||
|
||||
protected override object? GetKey(Song key)
|
||||
{
|
||||
@@ -35,7 +33,7 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
||||
return key.ImageName;
|
||||
}
|
||||
|
||||
return null;
|
||||
return "Default";
|
||||
}
|
||||
|
||||
protected override async ValueTask<BitmapImage?> FetchAsync(Song key, CancellationToken cancellationToken)
|
||||
@@ -43,7 +41,7 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
||||
SongPictureInfo? songPictureInfo = await audioImageExtractor.ExtractImageAsync(key.FileName, cancellationToken);
|
||||
|
||||
if (songPictureInfo == null)
|
||||
return null;
|
||||
return GetDefaultBitmapImage();
|
||||
|
||||
using MemoryStream stream = new(songPictureInfo.Data);
|
||||
|
||||
@@ -57,6 +55,18 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
private BitmapImage GetDefaultBitmapImage()
|
||||
{
|
||||
Uri uri = new("ms-appx:///Assets/Default.png", UriKind.Absolute);
|
||||
|
||||
BitmapImage bitmapImage = new();
|
||||
bitmapImage.DecodePixelWidth = GetDecodePixelWidth(bitmapImage);
|
||||
bitmapImage.DecodePixelHeight = GetDecodePixelHeight(bitmapImage);
|
||||
bitmapImage.UriSource = uri;
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
private int GetDecodePixelWidth(BitmapImage bitmapImage)
|
||||
{
|
||||
int originalImageWidth = bitmapImage.PixelWidth;
|
||||
|
||||
Reference in New Issue
Block a user