mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 06:56:27 +00:00
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:
parent
aa8e940726
commit
5ccef6fd14
@ -84,21 +84,21 @@ namespace SpotifyAPI.Example
|
|||||||
if (track.IsAd())
|
if (track.IsAd())
|
||||||
return; //Don't process further, maybe null values
|
return; //Don't process further, maybe null values
|
||||||
|
|
||||||
titleLinkLabel.Text = track.TrackResource.Name;
|
titleLinkLabel.Text = track.TrackResource?.Name;
|
||||||
titleLinkLabel.Tag = track.TrackResource.Uri;
|
titleLinkLabel.Tag = track.TrackResource?.Uri;
|
||||||
|
|
||||||
artistLinkLabel.Text = track.ArtistResource.Name;
|
artistLinkLabel.Text = track.ArtistResource?.Name;
|
||||||
artistLinkLabel.Tag = track.ArtistResource.Uri;
|
artistLinkLabel.Tag = track.ArtistResource?.Uri;
|
||||||
|
|
||||||
albumLinkLabel.Text = track.AlbumResource.Name;
|
albumLinkLabel.Text = track.AlbumResource?.Name;
|
||||||
albumLinkLabel.Tag = track.AlbumResource.Uri;
|
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);
|
bigAlbumPicture.Image = track.AlbumResource != null ? await track.GetAlbumArtAsync(AlbumArtSize.Size640) : null;
|
||||||
smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
|
smallAlbumPicture.Image = track.AlbumResource != null ? await track.GetAlbumArtAsync(AlbumArtSize.Size160) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePlayingStatus(bool playing)
|
public void UpdatePlayingStatus(bool playing)
|
||||||
|
@ -38,6 +38,15 @@ namespace SpotifyAPI.Local.Models
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Returns a URL to the album cover in the provided size
|
/// Returns a URL to the album cover in the provided size
|
||||||
|
@ -107,7 +107,8 @@ namespace SpotifyAPI.Local
|
|||||||
}
|
}
|
||||||
if (newStatusResponse.Track != null && _eventStatusResponse.Track != null)
|
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()
|
OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user