I'm trying to create cool visualization to music using the Spotify Web API(https://developer.spotify.com/documentation/web-api/reference/).
What I'm trying, is to first fetch what the user is playing, what's their progress and then I fetch the track analysis as well.
Fetching the currently played song is possible on this endpoint: https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/
The important stuff for me from the response is basically this:
{
"id": H7sbas7Gda98sh...., //ID of the song
"timestamp": 1490252122574, //unix timestamp when the data is fetched
"progress_ms": 42567 //The progress of the track in milliseconds
}
Obviously some time elapses between the request and the time I parse the response in my application. So the plan is that I synchronize the music this way:
const auto current_time = get_current_unix_timestamp();
const auto difference = current_time - timestamp; //the timestamp that is in the response
const offset = progress_ms + difference; //the progress_ms that is in the response
The theory is cool but it seems like the clock between the servers and on my system is not synchronized because I usually get values like -1638 for difference which is obviously not good because that would mean that I parsed the data sooner than it was fetched.
So my question is that what options do I have to synchronize my clock to Spotify servers? If it's not possible what options do I have to be able to synchronize the music properly? I couldn't find anything in Spotify documentation, although it should be possible because there are already some existing applications that do the same what I'm trying to do(e.g.: https://www.kaleidosync.com/)