Skip to content

Commit

Permalink
(#99) Refine albumart loading error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 4, 2024
1 parent b7d157f commit 9611a95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions Sources/Stylophone.Common/Services/AlbumArtService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,26 @@ internal async Task<SKBitmap> LoadImageFromFile(string fileName)

private SKBitmap ImageFromBytes(byte[] bytes)
{
SKBitmap image = SKBitmap.Decode(bytes);
try
{
SKBitmap image = SKBitmap.Decode(bytes);

// Resize overly large images to reduce OOM risk. Is 2048 too small ?
if (image.Width > 2048)
if (image == null)
return null;

// Resize overly large images to reduce OOM risk. Is 2048 too small ?
if (image.Width > 2048)
{
image.Resize(new SKImageInfo(2048, 2048 * image.Height / image.Width), SKFilterQuality.High);
}
return image;
}
catch (Exception e)
{
image.Resize(new SKImageInfo(2048, 2048 * image.Height / image.Width), SKFilterQuality.High);
Debug.WriteLine("Exception caught while loading albumart from MPD response: " + e);
_notificationService.ShowErrorNotification(e);
return null;
}
return image;
}

}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Stylophone/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
OffContent=""
OnContent="" />

<toolkit:SettingsExpander.ItemsFooter>
<toolkit:SettingsExpander.Items>
<toolkit:SettingsCard CornerRadius="0" Margin="-1,0"
Header="{x:Bind strings:Resources.SettingsLocalPlaybackPortHeader}"
Description="{x:Bind strings:Resources.SettingsLocalPlaybackPortText}">
Expand All @@ -110,7 +110,7 @@
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.LocalPlaybackPort, Mode=TwoWay}" />
</toolkit:SettingsCard>
</toolkit:SettingsExpander.ItemsFooter>
</toolkit:SettingsExpander.Items>
</toolkit:SettingsExpander>

<!-- DB/Art -->
Expand Down

0 comments on commit 9611a95

Please sign in to comment.