Fixed track change event not firing correctly

This commit is contained in:
Jonas Dellinger 2018-05-06 14:46:05 +02:00
parent 35b531ec2b
commit 6646f8d4a8
2 changed files with 10 additions and 12 deletions

View File

@ -30,14 +30,7 @@ namespace SpotifyAPI.Local.Models
/// 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"

View File

@ -54,6 +54,7 @@ namespace SpotifyAPI.Local
private readonly RemoteHandler _rh;
private Timer _eventTimer;
private StatusResponse _eventStatusResponse;
private Track _eventStatusTrack;
public event EventHandler<TrackChangeEventArgs> 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();
}