How can I tell if a song has ended or the next button was clicked with the spotify API?

一个人想着一个人 提交于 2019-12-11 10:35:55

问题


I'm using the Spotify API to develop an app for the desktop Spotify application on OSX. I've been beating my head against the wall trying to figure out how to tell if a song has ended and trigger another track to play.

Here's my event listener code:

models.player.observe(models.EVENT.CHANGE, function(event) {
    console.debug(event);
    if(event.data.playstate == false){
        $('.wholikes').remove();
        getTrack();
    }               
});

I guess I need to be looking at event.data, but when i check the inspector it has the same properties no matter what change it is observing. The type is set to 'playerStateChanged' which is not specific. I'm looking to trigger a new track at the end of a song or when the next button is pressed, but not when a user changes the scrubber to a different part of the song. Any ideas? I've check the documentation thoroughly and can't find this anywhere.


回答1:


When the event you're observing fires, check the player object's track property (models.player.track). When the track changes, you should find this changed to the next track if there is one, or null. At this point, you can start the next track.



来源:https://stackoverflow.com/questions/14009006/how-can-i-tell-if-a-song-has-ended-or-the-next-button-was-clicked-with-the-spoti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!