diff --git a/SpotifyAPI.Example/LocalControl.Designer.cs b/SpotifyAPI.Example/LocalControl.Designer.cs index 1b11cf85..fbe7dcb5 100644 --- a/SpotifyAPI.Example/LocalControl.Designer.cs +++ b/SpotifyAPI.Example/LocalControl.Designer.cs @@ -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; } } diff --git a/SpotifyAPI.Example/LocalControl.cs b/SpotifyAPI.Example/LocalControl.cs index 3acf36c2..bb66fd8e 100644 --- a/SpotifyAPI.Example/LocalControl.cs +++ b/SpotifyAPI.Example/LocalControl.cs @@ -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); } diff --git a/SpotifyAPI/Local/Models/Track.cs b/SpotifyAPI/Local/Models/Track.cs index 355aa422..e8451d32 100644 --- a/SpotifyAPI/Local/Models/Track.cs +++ b/SpotifyAPI/Local/Models/Track.cs @@ -21,6 +21,15 @@ namespace SpotifyAPI.Local.Models [JsonProperty("track_type")] public string TrackType { get; set; } + /// + /// Checks if the track is an advert + /// + /// true if the track is an advert, fals otherwise + public bool IsAd() + { + return TrackType == "ad"; + } + /// /// Returns a URL to the album cover in the provided size /// diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs index 8d46c86a..9ca4feab 100644 --- a/SpotifyAPI/Local/SpotifyLocalAPI.cs +++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs @@ -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 });