Fixed crash on adverts, Closes #34

This commit is contained in:
Johnny Dellinger @PC 2015-10-01 17:28:40 +02:00
parent cd4eddf288
commit d1f1923738
4 changed files with 34 additions and 10 deletions

View File

@ -60,6 +60,7 @@
this.artistLinkLabel = new System.Windows.Forms.LinkLabel(); this.artistLinkLabel = new System.Windows.Forms.LinkLabel();
this.titleLinkLabel = new System.Windows.Forms.LinkLabel(); this.titleLinkLabel = new System.Windows.Forms.LinkLabel();
this.smallAlbumPicture = new System.Windows.Forms.PictureBox(); this.smallAlbumPicture = new System.Windows.Forms.PictureBox();
this.advertLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bigAlbumPicture)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@ -307,6 +308,7 @@
// //
// groupBox2 // groupBox2
// //
this.groupBox2.Controls.Add(this.advertLabel);
this.groupBox2.Controls.Add(this.timeLabel); this.groupBox2.Controls.Add(this.timeLabel);
this.groupBox2.Controls.Add(this.timeProgressBar); this.groupBox2.Controls.Add(this.timeProgressBar);
this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label5);
@ -418,6 +420,14 @@
this.smallAlbumPicture.TabIndex = 5; this.smallAlbumPicture.TabIndex = 5;
this.smallAlbumPicture.TabStop = false; 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 // LocalControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -472,5 +482,6 @@
private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label repeatShuffleLabel; private System.Windows.Forms.Label repeatShuffleLabel;
private System.Windows.Forms.Label advertLabel;
} }
} }

View File

@ -78,6 +78,12 @@ namespace SpotifyAPI.Example
{ {
_currentTrack = track; _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.Text = track.TrackResource.Name;
titleLinkLabel.Tag = track.TrackResource.Uri; titleLinkLabel.Tag = track.TrackResource.Uri;
@ -87,8 +93,6 @@ namespace SpotifyAPI.Example
albumLinkLabel.Text = track.AlbumResource.Name; albumLinkLabel.Text = track.AlbumResource.Name;
albumLinkLabel.Tag = track.AlbumResource.Uri; albumLinkLabel.Tag = track.AlbumResource.Uri;
timeProgressBar.Maximum = track.Length;
bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640); bigAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size640);
smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160); smallAlbumPicture.Image = await track.GetAlbumArtAsync(AlbumArtSize.Size160);
} }

View File

@ -21,6 +21,15 @@ namespace SpotifyAPI.Local.Models
[JsonProperty("track_type")] [JsonProperty("track_type")]
public string TrackType { get; set; } 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> /// <summary>
/// Returns a URL to the album cover in the provided size /// Returns a URL to the album cover in the provided size
/// </summary> /// </summary>

View File

@ -95,33 +95,33 @@ namespace SpotifyAPI.Local
} }
if (newStatusResponse.Track != null && _eventStatusResponse.Track != null) 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, OldTrack = _eventStatusResponse.Track,
NewTrack = newStatusResponse.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 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, OldVolume = _eventStatusResponse.Volume,
NewVolume = newStatusResponse.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 TrackTime = newStatusResponse.PlayingPosition
}); });