From ae9e4a5d91017affe4766186cc65aa91e015c5d5 Mon Sep 17 00:00:00 2001
From: Alessandro Attard Barbini <11708634+aleab@users.noreply.github.com>
Date: Fri, 15 Dec 2017 16:24:47 +0100
Subject: [PATCH 1/2] Raise OnTrackChange event for "other" tracks as well
---
SpotifyAPI/Local/Models/Track.cs | 9 +++++++++
SpotifyAPI/Local/SpotifyLocalAPI.cs | 3 ++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/SpotifyAPI/Local/Models/Track.cs b/SpotifyAPI/Local/Models/Track.cs
index 452429309..ea50741f1 100755
--- a/SpotifyAPI/Local/Models/Track.cs
+++ b/SpotifyAPI/Local/Models/Track.cs
@@ -38,6 +38,15 @@ public bool IsAd()
return true;
return false;
}
+
+ ///
+ /// Checks if the track id of type "other"
+ ///
+ /// true if the track is neither an advert nor a normal track, for example a podcast
+ public bool IsOtherTrackType()
+ {
+ return TrackType == "other";
+ }
///
/// Returns a URL to the album cover in the provided size
diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs
index 245ca1c28..28b0777ce 100644
--- a/SpotifyAPI/Local/SpotifyLocalAPI.cs
+++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs
@@ -107,7 +107,8 @@ private void ElapsedTick(object sender, ElapsedEventArgs e)
}
if (newStatusResponse.Track != null && _eventStatusResponse.Track != null)
{
- if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusResponse.Track.TrackResource?.Uri)
+ if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusResponse.Track.TrackResource?.Uri ||
+ newStatusResponse.Track.IsOtherTrackType() && newStatusResponse.Track.Length != this._eventStatusResponse.Track.Length)
{
OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
{
From 0013f6756db59339a0d684c4cdf7fc3129449958 Mon Sep 17 00:00:00 2001
From: Alessandro Attard Barbini <11708634+aleab@users.noreply.github.com>
Date: Fri, 15 Dec 2017 16:28:55 +0100
Subject: [PATCH 2/2] Add null checks in Example project
---
SpotifyAPI.Example/LocalControl.cs | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/SpotifyAPI.Example/LocalControl.cs b/SpotifyAPI.Example/LocalControl.cs
index a76df043b..83ac80c3d 100644
--- a/SpotifyAPI.Example/LocalControl.cs
+++ b/SpotifyAPI.Example/LocalControl.cs
@@ -84,21 +84,21 @@ public async void UpdateTrack(Track track)
if (track.IsAd())
return; //Don't process further, maybe null values
- titleLinkLabel.Text = track.TrackResource.Name;
- titleLinkLabel.Tag = track.TrackResource.Uri;
+ titleLinkLabel.Text = track.TrackResource?.Name;
+ titleLinkLabel.Tag = track.TrackResource?.Uri;
- artistLinkLabel.Text = track.ArtistResource.Name;
- artistLinkLabel.Tag = track.ArtistResource.Uri;
+ artistLinkLabel.Text = track.ArtistResource?.Name;
+ artistLinkLabel.Tag = track.ArtistResource?.Uri;
- albumLinkLabel.Text = track.AlbumResource.Name;
- albumLinkLabel.Tag = track.AlbumResource.Uri;
+ albumLinkLabel.Text = track.AlbumResource?.Name;
+ albumLinkLabel.Tag = track.AlbumResource?.Uri;
- SpotifyUri uri = track.TrackResource.ParseUri();
+ SpotifyUri uri = track.TrackResource?.ParseUri();
- trackInfoBox.Text = $@"Track Info - {uri.Id}";
+ trackInfoBox.Text = $@"Track Info - {uri?.Id}";
- bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640);
- smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
+ bigAlbumPicture.Image = track.AlbumResource != null ? await track.GetAlbumArtAsync(AlbumArtSize.Size640) : null;
+ smallAlbumPicture.Image = track.AlbumResource != null ? await track.GetAlbumArtAsync(AlbumArtSize.Size160) : null;
}
public void UpdatePlayingStatus(bool playing)