Pausing Spotify while YouTube is playing and starting it when YouTube stops
Solution 1:
I built mute.fm (http://www.mutefm.com/) to solve this problem. It works with iTunes, Spotify, and many other music players and will mute/pause it for YouTube or any other video or foreground sound.
Solution 2:
Haven't tested it, but I think it's doable.
First, add this wrapper to your spotify: https://github.com/johanlindquist/jahspotify. This will give you a REST interface to control playback.
Now, create a chrome (I assume that's what you're using. If not, there are probably similar options for other browsers as well) extension that works for everything on YouTube's domain and add this: https://stackoverflow.com/q/8152814/1456578. Change the code to pause/resume spotify when a certain event happens on YT player.
As I'm intrested in a solution myself as well, I'll probably try it out sometime soon and will then update this answer with the results. Will most likely create/use a lightweight node server to wrap Spotify instead, because Tomcat seems like an overkill and all you (I) actually need is the play/pause functionality.