mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-25 15:36: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
|
/// Checks if the track is an advert
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>true if the track is an advert, false otherwise</returns>
|
/// <returns>true if the track is an advert, false otherwise</returns>
|
||||||
public bool IsAd()
|
public bool IsAd() => TrackType == "ad" || Length == 0;
|
||||||
{
|
|
||||||
if (TrackType == "ad")
|
|
||||||
return true;
|
|
||||||
if (Length == 0)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the track id of type "other"
|
/// Checks if the track id of type "other"
|
||||||
|
@ -54,6 +54,7 @@ namespace SpotifyAPI.Local
|
|||||||
private readonly RemoteHandler _rh;
|
private readonly RemoteHandler _rh;
|
||||||
private Timer _eventTimer;
|
private Timer _eventTimer;
|
||||||
private StatusResponse _eventStatusResponse;
|
private StatusResponse _eventStatusResponse;
|
||||||
|
private Track _eventStatusTrack;
|
||||||
|
|
||||||
public event EventHandler<TrackChangeEventArgs> OnTrackChange;
|
public event EventHandler<TrackChangeEventArgs> OnTrackChange;
|
||||||
|
|
||||||
@ -105,14 +106,14 @@ namespace SpotifyAPI.Local
|
|||||||
_eventTimer.Start();
|
_eventTimer.Start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (newStatusResponse.Track != null && _eventStatusResponse.Track != null)
|
if (newStatusResponse.Track != null && _eventStatusTrack != null)
|
||||||
{
|
{
|
||||||
if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusResponse.Track.TrackResource?.Uri ||
|
if (newStatusResponse.Track.TrackResource?.Uri != _eventStatusTrack.TrackResource?.Uri ||
|
||||||
newStatusResponse.Track.IsOtherTrackType() && newStatusResponse.Track.Length != _eventStatusResponse.Track.Length)
|
newStatusResponse.Track.IsOtherTrackType() && newStatusResponse.Track.Length != _eventStatusTrack.Length)
|
||||||
{
|
{
|
||||||
OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
|
OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
|
||||||
{
|
{
|
||||||
OldTrack = _eventStatusResponse.Track,
|
OldTrack = _eventStatusTrack,
|
||||||
NewTrack = newStatusResponse.Track
|
NewTrack = newStatusResponse.Track
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -140,6 +141,10 @@ namespace SpotifyAPI.Local
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
_eventStatusResponse = newStatusResponse;
|
_eventStatusResponse = newStatusResponse;
|
||||||
|
if (newStatusResponse.Track != null)
|
||||||
|
{
|
||||||
|
_eventStatusTrack = newStatusResponse.Track;
|
||||||
|
}
|
||||||
_eventTimer.Start();
|
_eventTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user