From 6646f8d4a87b1efa9d5a3fe79c0d2ce0562cca03 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Sun, 6 May 2018 14:46:05 +0200 Subject: [PATCH] Fixed track change event not firing correctly --- SpotifyAPI/Local/Models/Track.cs | 9 +-------- SpotifyAPI/Local/SpotifyLocalAPI.cs | 13 +++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/SpotifyAPI/Local/Models/Track.cs b/SpotifyAPI/Local/Models/Track.cs index b6b93b1d..2f489276 100755 --- a/SpotifyAPI/Local/Models/Track.cs +++ b/SpotifyAPI/Local/Models/Track.cs @@ -30,14 +30,7 @@ namespace SpotifyAPI.Local.Models /// Checks if the track is an advert /// /// true if the track is an advert, false otherwise - public bool IsAd() - { - if (TrackType == "ad") - return true; - if (Length == 0) - return true; - return false; - } + public bool IsAd() => TrackType == "ad" || Length == 0; /// /// Checks if the track id of type "other" diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs index 813d84b4..4ebba799 100644 --- a/SpotifyAPI/Local/SpotifyLocalAPI.cs +++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs @@ -54,6 +54,7 @@ namespace SpotifyAPI.Local private readonly RemoteHandler _rh; private Timer _eventTimer; private StatusResponse _eventStatusResponse; + private Track _eventStatusTrack; public event EventHandler OnTrackChange; @@ -105,14 +106,14 @@ namespace SpotifyAPI.Local _eventTimer.Start(); return; } - if (newStatusResponse.Track != null && _eventStatusResponse.Track != null) + if (newStatusResponse.Track != null && _eventStatusTrack != null) { - if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusResponse.Track.TrackResource?.Uri || - newStatusResponse.Track.IsOtherTrackType() && newStatusResponse.Track.Length != _eventStatusResponse.Track.Length) + if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusTrack.TrackResource?.Uri || + newStatusResponse.Track.IsOtherTrackType() && newStatusResponse.Track.Length != _eventStatusTrack.Length) { OnTrackChange?.Invoke(this, new TrackChangeEventArgs() { - OldTrack = _eventStatusResponse.Track, + OldTrack = _eventStatusTrack, NewTrack = newStatusResponse.Track }); } @@ -140,6 +141,10 @@ namespace SpotifyAPI.Local }); } _eventStatusResponse = newStatusResponse; + if (newStatusResponse.Track != null) + { + _eventStatusTrack = newStatusResponse.Track; + } _eventTimer.Start(); }