Skip to content

Commit

Permalink
fix nullability handling of album cover url
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Apr 11, 2024
1 parent cee9a52 commit 526b314
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion MusicX.Shared/Player/AlbumId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MusicX.Shared.Player;
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic, SkipConstructor = true)]
[ProtoInclude(100, typeof(BoomAlbumId))]
[ProtoInclude(101, typeof(VkAlbumId))]
public abstract record AlbumId(string Name, string CoverUrl, string? BigCoverUrl);
public abstract record AlbumId(string Name, string? CoverUrl, string? BigCoverUrl);

[ProtoContract(ImplicitFields = ImplicitFields.AllPublic, SkipConstructor = true)]
public sealed record VkAlbumId
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
Height="45"
CornerRadius="5">
<Border.Background>
<ImageBrush ImageSource="{Binding AlbumId.CoverUrl}" />
<ImageBrush ImageSource="{Binding AlbumId.CoverUrl, FallbackValue={x:Null}}" />
</Border.Background>
</Border>
<TextBlock
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private async void PlayerService_TrackChangedEvent(object? sender, EventArgs e)



if (playerService.CurrentTrack.AlbumId != null)
if (playerService.CurrentTrack.AlbumId?.CoverUrl != null)
{
var amim = (Storyboard)(this.Resources["BackgroundAmimate"]);
amim.Begin();
Expand Down
23 changes: 13 additions & 10 deletions MusicX/Services/DownloaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,21 @@ private async Task AddMetadataAsync(PlaylistTrack audio, string filePath, Cancel
if (audio.AlbumId != null)
{
tfile.Tag.Album = audio.AlbumId.Name;

var thumbData = await _httpClient.GetByteArrayAsync(audio.AlbumId.BigCoverUrl ?? audio.AlbumId.CoverUrl, cancellationToken);

var cover = new AttachedPictureFrame
if (audio.AlbumId.CoverUrl != null)
{
Type = PictureType.FrontCover,
Description = "Cover",
MimeType = MediaTypeNames.Image.Jpeg,
Data = thumbData,
TextEncoding = StringType.UTF16
};
tfile.Tag.Pictures = new IPicture[] {cover};
var thumbData = await _httpClient.GetByteArrayAsync(audio.AlbumId.BigCoverUrl ?? audio.AlbumId.CoverUrl, cancellationToken);

var cover = new AttachedPictureFrame
{
Type = PictureType.FrontCover,
Description = "Cover",
MimeType = MediaTypeNames.Image.Jpeg,
Data = thumbData,
TextEncoding = StringType.UTF16
};
tfile.Tag.Pictures = new IPicture[] {cover};
}
}

tfile.Save();
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Services/Player/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private async Task UpdateWindowsData()



if (CurrentTrack.AlbumId is not null)
if (CurrentTrack.AlbumId?.CoverUrl is not null)
{
player.SystemMediaTransportControls.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(CurrentTrack.AlbumId.CoverUrl));

Expand Down
4 changes: 2 additions & 2 deletions MusicX/Views/FullScreenWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async void SetData()
PositionSlider.Maximum = playerService.CurrentTrack!.Data.Duration.TotalSeconds;


if (playerService.CurrentTrack.AlbumId != null)
if (playerService.CurrentTrack.AlbumId?.CoverUrl != null)
{

var bitmapImage = new BitmapImage(new Uri(playerService.CurrentTrack.AlbumId.BigCoverUrl ?? playerService.CurrentTrack.AlbumId.CoverUrl));
Expand All @@ -96,7 +96,7 @@ private async void SetData()

if (playerService.NextPlayTrack != null)
{
if (playerService.NextPlayTrack.AlbumId != null)
if (playerService.NextPlayTrack.AlbumId?.CoverUrl != null)
{
NextTrackCover.ImageSource = new BitmapImage(new Uri(playerService.NextPlayTrack.AlbumId.CoverUrl));
NextTrackNote.Visibility = Visibility.Collapsed;
Expand Down

0 comments on commit 526b314

Please sign in to comment.