Music Player Daemon Community Wiki

Bind notebook media keys to MPD using DBUS

525pages on
this wiki
Add New Page
Add New Page Talk0
#!/usr/bin/env python
This script handles media key pressing events on DBus
(Fn+Play/Pause/Stop/Forward/Prev) by calling mpc with
corresponding argument.
Tested on Acer aspire 3935 with Ubuntu 10.10. Both laptop
media keys and bluetooth stereo garniture media buttons (BT56) work.

Author: Batalov Sergey, 2011-02-07 svbatalov at gmail dot com.

Here is a patch to use it with (see ):
@@ -99,9 +99,13 @@
-            "previous"
+           "previous",
+            "prev"
+    def prev(self):
+       self.previous()
     def info(self):
         Show song information only

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import os

mpc = 'mpc'   # Or modified to accept the 'prev' command.
def KeyHandler(x,y):
	def run(cmd):
		return lambda: os.system(mpc + ' ' + cmd)
	'Play': run('toggle'),
	'Stop': run('stop'),
	'Next': run('next'),
	'Previous': run('prev')	}[y]()

bus = dbus.SessionBus()
loop = gobject.MainLoop()

#dbus info obtained using dbus-monitor
		None,                                   #signal name. None means any
		'org.gnome.SettingsDaemon.MediaKeys',   #interface
		None, 			           	#sender bus name. any. :1.7 usually
		'/org/gnome/SettingsDaemon/MediaKeys'   #path

Also on Fandom

Random Wiki