mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 15:06:26 +00:00
Fixed track change event not firing correctly
This commit is contained in:
parent
35b531ec2b
commit
6646f8d4a8
@ -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"
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user