You should trigger the `track_playback_ended` event before changing the current track. The event trigger uses the current track to include the track that ended in the event. This is used at least by the Last.fm scrobbler.