Moved fetching image to background thread.
This commit is contained in:
@@ -40,7 +40,9 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
|||||||
|
|
||||||
protected override async ValueTask<BitmapImage?> FetchAsync(Song key, CancellationToken cancellationToken)
|
protected override async ValueTask<BitmapImage?> FetchAsync(Song key, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
SongPictureInfo? songPictureInfo = await audioImageExtractor.ExtractImageAsync(key.FileName, cancellationToken);
|
SongPictureInfo? songPictureInfo = await Task.Run(
|
||||||
|
() => audioImageExtractor.ExtractImageAsync(key.FileName, cancellationToken),
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
if (songPictureInfo == null)
|
if (songPictureInfo == null)
|
||||||
return GetDefaultBitmapImage();
|
return GetDefaultBitmapImage();
|
||||||
@@ -51,8 +53,17 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
|||||||
|
|
||||||
await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
|
await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
|
||||||
|
|
||||||
bitmapImage.DecodePixelWidth = GetDecodePixelWidth(bitmapImage);
|
int decodePixelWidth = GetDecodePixelWidth(bitmapImage);
|
||||||
bitmapImage.DecodePixelHeight = GetDecodePixelHeight(bitmapImage);
|
int decodePixelHeight = GetDecodePixelHeight(bitmapImage);
|
||||||
|
|
||||||
|
if (decodePixelWidth > 0 || decodePixelHeight > 0)
|
||||||
|
{
|
||||||
|
bitmapImage.DecodePixelWidth = decodePixelWidth;
|
||||||
|
bitmapImage.DecodePixelHeight = decodePixelHeight;
|
||||||
|
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
|
||||||
|
}
|
||||||
|
|
||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
}
|
}
|
||||||
@@ -62,8 +73,6 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
|||||||
Uri uri = new("ms-appx:///Assets/Default.png", UriKind.Absolute);
|
Uri uri = new("ms-appx:///Assets/Default.png", UriKind.Absolute);
|
||||||
|
|
||||||
BitmapImage bitmapImage = new();
|
BitmapImage bitmapImage = new();
|
||||||
bitmapImage.DecodePixelWidth = GetDecodePixelWidth(bitmapImage);
|
|
||||||
bitmapImage.DecodePixelHeight = GetDecodePixelHeight(bitmapImage);
|
|
||||||
bitmapImage.UriSource = uri;
|
bitmapImage.UriSource = uri;
|
||||||
|
|
||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
@@ -99,7 +108,10 @@ public class AudioBitmapImageCache(IAudioImageExtractor audioImageExtractor) : M
|
|||||||
|
|
||||||
protected override long GetEntrySize(BitmapImage entry)
|
protected override long GetEntrySize(BitmapImage entry)
|
||||||
{
|
{
|
||||||
return entry.DecodePixelWidth * entry.DecodePixelHeight;
|
int width = entry.DecodePixelWidth > 0 ? entry.DecodePixelWidth : entry.PixelWidth;
|
||||||
|
int height = entry.DecodePixelHeight > 0 ? entry.DecodePixelHeight : entry.PixelHeight;
|
||||||
|
|
||||||
|
return (long)width * height * 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user