Raise OnTrackChange event for "other" tracks as well (#204)

* Raise OnTrackChange event for "other" tracks as well

* Add null checks in Example project
This commit is contained in:
Alessandro Attard Barbini 2018-01-10 14:56:58 +01:00 committed by Jonas Dellinger
parent aa8e940726
commit 5ccef6fd14
3 changed files with 21 additions and 11 deletions

View File

@ -84,21 +84,21 @@ namespace SpotifyAPI.Example
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)

View File

@ -39,6 +39,15 @@ namespace SpotifyAPI.Local.Models
return false;
}
/// <summary>
/// Checks if the track id of type "other"
/// </summary>
/// <returns>true if the track is neither an advert nor a normal track, for example a podcast</returns>
public bool IsOtherTrackType()
{
return TrackType == "other";
}
/// <summary>
/// Returns a URL to the album cover in the provided size
/// </summary>

View File

@ -107,7 +107,8 @@ namespace SpotifyAPI.Local
}
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()
{