mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Fixed crash on adverts, Closes #34
This commit is contained in:
parent
cd4eddf288
commit
d1f1923738
11
SpotifyAPI.Example/LocalControl.Designer.cs
generated
11
SpotifyAPI.Example/LocalControl.Designer.cs
generated
@ -60,6 +60,7 @@
|
||||
this.artistLinkLabel = new System.Windows.Forms.LinkLabel();
|
||||
this.titleLinkLabel = new System.Windows.Forms.LinkLabel();
|
||||
this.smallAlbumPicture = new System.Windows.Forms.PictureBox();
|
||||
this.advertLabel = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).BeginInit();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
@ -307,6 +308,7 @@
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.advertLabel);
|
||||
this.groupBox2.Controls.Add(this.timeLabel);
|
||||
this.groupBox2.Controls.Add(this.timeProgressBar);
|
||||
this.groupBox2.Controls.Add(this.label5);
|
||||
@ -418,6 +420,14 @@
|
||||
this.smallAlbumPicture.TabIndex = 5;
|
||||
this.smallAlbumPicture.TabStop = false;
|
||||
//
|
||||
// advertLabel
|
||||
//
|
||||
this.advertLabel.AutoSize = true;
|
||||
this.advertLabel.Location = new System.Drawing.Point(6, 67);
|
||||
this.advertLabel.Name = "advertLabel";
|
||||
this.advertLabel.Size = new System.Drawing.Size(0, 17);
|
||||
this.advertLabel.TabIndex = 31;
|
||||
//
|
||||
// LocalControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@ -472,5 +482,6 @@
|
||||
private System.Windows.Forms.Label label11;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.Label repeatShuffleLabel;
|
||||
private System.Windows.Forms.Label advertLabel;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,12 @@ namespace SpotifyAPI.Example
|
||||
{
|
||||
_currentTrack = track;
|
||||
|
||||
advertLabel.Text = track.IsAd() ? "ADVERT" : "";
|
||||
timeProgressBar.Maximum = track.Length;
|
||||
|
||||
if (track.IsAd())
|
||||
return; //Don't process further, maybe null values
|
||||
|
||||
titleLinkLabel.Text = track.TrackResource.Name;
|
||||
titleLinkLabel.Tag = track.TrackResource.Uri;
|
||||
|
||||
@ -87,8 +93,6 @@ namespace SpotifyAPI.Example
|
||||
albumLinkLabel.Text = track.AlbumResource.Name;
|
||||
albumLinkLabel.Tag = track.AlbumResource.Uri;
|
||||
|
||||
timeProgressBar.Maximum = track.Length;
|
||||
|
||||
bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640);
|
||||
smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
|
||||
}
|
||||
|
@ -21,6 +21,15 @@ namespace SpotifyAPI.Local.Models
|
||||
[JsonProperty("track_type")]
|
||||
public string TrackType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the track is an advert
|
||||
/// </summary>
|
||||
/// <returns>true if the track is an advert, fals otherwise</returns>
|
||||
public bool IsAd()
|
||||
{
|
||||
return TrackType == "ad";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a URL to the album cover in the provided size
|
||||
/// </summary>
|
||||
|
@ -95,33 +95,33 @@ namespace SpotifyAPI.Local
|
||||
}
|
||||
if (newStatusResponse.Track != null && _eventStatusResponse.Track != null)
|
||||
{
|
||||
if (newStatusResponse.Track.TrackResource.Name != _eventStatusResponse.Track.TrackResource.Name && OnTrackChange != null)
|
||||
if (newStatusResponse.Track.TrackResource?.Name != _eventStatusResponse.Track.TrackResource?.Name)
|
||||
{
|
||||
OnTrackChange(new TrackChangeEventArgs()
|
||||
OnTrackChange?.Invoke(new TrackChangeEventArgs()
|
||||
{
|
||||
OldTrack = _eventStatusResponse.Track,
|
||||
NewTrack = newStatusResponse.Track
|
||||
});
|
||||
}
|
||||
}
|
||||
if (newStatusResponse.Playing != _eventStatusResponse.Playing && OnPlayStateChange != null)
|
||||
if (newStatusResponse.Playing != _eventStatusResponse.Playing)
|
||||
{
|
||||
OnPlayStateChange(new PlayStateEventArgs()
|
||||
OnPlayStateChange?.Invoke(new PlayStateEventArgs()
|
||||
{
|
||||
Playing = newStatusResponse.Playing
|
||||
});
|
||||
}
|
||||
if (newStatusResponse.Volume != _eventStatusResponse.Volume && OnVolumeChange != null)
|
||||
if (newStatusResponse.Volume != _eventStatusResponse.Volume)
|
||||
{
|
||||
OnVolumeChange(new VolumeChangeEventArgs()
|
||||
OnVolumeChange?.Invoke(new VolumeChangeEventArgs()
|
||||
{
|
||||
OldVolume = _eventStatusResponse.Volume,
|
||||
NewVolume = newStatusResponse.Volume
|
||||
});
|
||||
}
|
||||
if (newStatusResponse.PlayingPosition != _eventStatusResponse.PlayingPosition && OnTrackTimeChange != null)
|
||||
if (newStatusResponse.PlayingPosition != _eventStatusResponse.PlayingPosition)
|
||||
{
|
||||
OnTrackTimeChange(new TrackTimeChangeEventArgs()
|
||||
OnTrackTimeChange?.Invoke(new TrackTimeChangeEventArgs()
|
||||
{
|
||||
TrackTime = newStatusResponse.PlayingPosition
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user