As I have been experimenting with the docky python bindings, I created a small media control helper for Vagalume, a lightweight last.fm client. I found the vagalume DBus methods and signals to be mostly undocumented, but I found them lurking around after a quick look at some of the source code.
I created a smallish class with the help of the excellent PyGtk Notebook.
import dbus, gtk, gobject from dbus.mainloop.glib import DBusGMainLoop class vagalume: def __init__(self): dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus() self.player = self.bus.get_object("com.igalia.vagalume", "/com/igalia/vagalume") self.bus.add_signal_receiver(self.song_changed, dbus_interface="com.igalia.vagalume", signal_name="notify") def song_changed(self, *args): self.state = args if state == 'stopped': #do something when the player is stopped elif state == 'playing': self.artist = args  self.title = args  self.album = args  #do something with the data here... if __name__ == "__main__": app = vagalume() gtk.main()
I used the gtk mainloop for simplicity, but you could use
mainloop = gobject.MainLoop(is_running=True) mainloop.run()
If you want to use the signals for change of song etc, it would be best to modify
vagalume() to do what you want.
To interact with vagalume do something like:
vagalume = vagalume() #do anything you want with dbus. #take a look at http://gitorious.org/vagalume/vagalume/blobs/master/src/dbus.h #for all of the functions available vagalume.player.Play() vagalume.player.Skip() vagalume.player.LoveTrack() vagalume.player.BanTrack() vagalume.player.Stop()