Search code examples
objective-cmacositunesspotify

Receiving an event when other applications (iTunes or Spotify) do something


I'm pretty new to Objective-C and OSX development, so I'm still learning how to find these sort of answers out...

Is there a generalized library that allows you to receive events when specific actions are taken within other applications?

Specifically, I'm trying to receive events in my application when iTunes or Spotify start playing audio and stop playing audio.

I've implemented a Scripting Bridge for each application that allows me to fetch the status of the playback from each application, but I'd like to be able to receive events when actions I care about are taken - instead of having to poll for them constantly. Moreover, iTunes and Spotify are certainly two of the popular music players out there, but there are others (like Rdio, and MOG) that I'd like to support. Writing an implementation for every specific music player seems a little crazy - but maybe that's just what I have to do.

Any insight, tips, or links for good reading is also appreciated.

Thanks!


Solution

  • The Spotify client issues a distributed notification with the name com.spotify.client.PlaybackStateChanged when playback state changes, which contains a number of metadata keys each time it's called. You can watch for this in your application using NSDistributedNotificationCenter.

    iTunes also has one called com.apple.iTunes.playerInfo.