Broda Noel
Broda Noel

Reputation: 1960

How to know when the user changes the song with the Spotify API

I need to know when the user changes the song that is "currently playing".

Currently, I'm using https://api.spotify.com/v1/me/player/currently-playing to get the information about the song that is "currently playing". But, I need to know when it changes to the next one (not only because the song finished, but also when the user press NEXT SONG button).

My current workaround is to call the https://api.spotify.com/v1/me/player/currently-playing endpoint every second, but I'll be out of the rate limit if I do it very often.

Upvotes: 9

Views: 5670

Answers (1)

José M. Pérez
José M. Pérez

Reputation: 3279

You are doing it right. You need to poll the https://api.spotify.com/v1/me/player/currently-playing endpoint to detect changes in the playback state.

In some scenarios it can be suitable to use Spotify's web playback SDK, which exposes a player_state_changed event. For this to work the user needs to have a premium account and the playback needs to happen on the device created by the SDK.

Upvotes: 13

Related Questions