JMPerez / spotify-web-api-js

A client-side JS wrapper for the Spotify Web API
https://jmperezperez.com/spotify-web-api-js/
MIT License
1.86k stars 260 forks source link

Get to know when playback is starting #185

Closed mystermiam closed 3 years ago

mystermiam commented 3 years ago

Hello there!

The problem I'm trying to solve is :

"Using the Spotify web API /player endpoint, offering a usable progress-bar through a custom Spotify player".

I've understood that there is no way to get any realtime player updates from posted issues on the Spotify repository.

However, I'd like to know: Would be possible for one to know when the playback is starting ? I mean by that, when one can actually hear the song playing through the speakers, which is different than the request to "/player/play" being completed.

For now, I'm launching a timer to keep the progress bar updated when the request is completed, but it causes various annoying side effects... Also, I'd like to avoid polling the /player endpoint.

JMPerez commented 3 years ago

Thanks @mystermiam for the suggestion. This is not possible at the moment since that functionality is not provided by Spotify's API, so you are left with checking the playback state every few seconds.

This is for instance what I do in https://github.com/JMPerez/spotify-player (see https://github.com/JMPerez/spotify-player/blob/master/public/spotify-player.js#L73) used on these "now playing" visualizations.