Skip to content

Commit

Permalink
Fixed track change event not firing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyCrazy committed May 6, 2018
1 parent 35b531e commit 6646f8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
9 changes: 1 addition & 8 deletions SpotifyAPI/Local/Models/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public class Track
/// Checks if the track is an advert
/// </summary>
/// <returns>true if the track is an advert, false otherwise</returns>
public bool IsAd()
{
if (TrackType == "ad")
return true;
if (Length == 0)
return true;
return false;
}
public bool IsAd() => TrackType == "ad" || Length == 0;

/// <summary>
/// Checks if the track id of type "other"
Expand Down
13 changes: 9 additions & 4 deletions SpotifyAPI/Local/SpotifyLocalAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public ISynchronizeInvoke SynchronizingObject
private readonly RemoteHandler _rh;
private Timer _eventTimer;
private StatusResponse _eventStatusResponse;
private Track _eventStatusTrack;

public event EventHandler<TrackChangeEventArgs> OnTrackChange;

Expand Down Expand Up @@ -105,14 +106,14 @@ private void ElapsedTick(object sender, ElapsedEventArgs e)
_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
});
}
Expand Down Expand Up @@ -140,6 +141,10 @@ private void ElapsedTick(object sender, ElapsedEventArgs e)
});
}
_eventStatusResponse = newStatusResponse;
if (newStatusResponse.Track != null)
{
_eventStatusTrack = newStatusResponse.Track;
}
_eventTimer.Start();
}

Expand Down

0 comments on commit 6646f8d

Please sign in to comment.