How does the Spotify web browser button interact with the Spotify app?

browser, controls, javascript, spotify

Solution

The desktop runs a server at `*.spotilocal.com` on your computer, then on the web, the embed player (example) will choose a subdomain name (example: `fdxubmxkqp.spotilocal.com`).

It then makes request to the local server's API, examples:

https://fdxubmxkqp.spotilocal.com:4370/service/version.json
https://fdxubmxkqp.spotilocal.com:4370/simplecsrf/token.json

And it just returns some JSON:

{
"version": 9, 
"client_version": "1.0.10.107.gd0dfca3a"
}

See this screenshot for more info, or you can get the same info by going to news.spotify.com and using the Network inspector with `spotilocal` as a filter.

Problem

Check out this play button, written entirely it seems, using javascript: spotify play button. Notice that pressing play will cause Spotify to start playing music. OK, I figure that's done via some app-specific protocol link (like spotify://play), although I could be wrong. But the crazy part is that if you stop playing music in Spotify, the button will be updated in the browser to show that the music has stopped playing! How does that work? You can look at its source here.

Original source