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
The spotify play button long polls (over HTTPS) the spotify application running on localhost to update the state.