xmms2 track change detection for pynotify?

112 Views Asked by At

I have written this little script to show current track playing on xmms2 on a notification widget using xmms client and pynotify, so when i run it i can see the widget popup with current artist and title using xmmsclient methods.

Can anybody give some hints about how to detect track change to notify automatically without having to run the script manually?

1

There are 1 best solutions below

0
On BEST ANSWER

You connect the client library to a main loop, and register as a listener via the broadcast_ playback_current_id method. If you want the currently playing id when the script starts as well you can call the playback_current_id method.

Here is a small adaptation of tutorial6 in the xmms2-tutorial.git which uses the GLib Mainloop to drive the connection:

import xmmsclient
import xmmsclient.glib
import os
import sys
import gobject

def cb(result):
    if not result.is_error():
        print "Current: %(artist)s - %(title)s" % result.value()


ml = gobject.MainLoop(None, False)

xc = xmmsclient.XMMS("stackoverflow")
xc.connect()

conn = xmmsclient.glib.GLibConnector(xc)
xc.broadcast_playback_current_id(lambda r: xc.medialib_get_info(r.value(), cb))
ml.run()