Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- '''
- Created on 30.05.2012
- @author: Matteo Italia <mi_1@mitalia.net>
- '''
- import dbus
- import dbus.mainloop.glib
- import gobject
- app_name = 'mmkeys-mate2mpris2'
- Version=0.1
- MediaKeysObjName = 'org.mate.SettingsDaemon'
- MediaKeysObjectPath = '/org/mate/SettingsDaemon/MediaKeys'
- MediaKeysInterface = 'org.mate.SettingsDaemon.MediaKeys'
- MPRIS2Prefix = 'org.mpris.MediaPlayer2'
- ActionMappings = {
- 'Play': 'PlayPause',
- 'Pause': 'Pause',
- 'Stop': 'Stop',
- 'Next': 'Next',
- 'Previous': 'Previous'}
- def onMediaKeyPress(app_name, action):
- sb = dbus.SessionBus()
- # Get the compatible players
- players = [n for n in sb.list_names() if n.startswith(MPRIS2Prefix + ".") ]
- # Send them the command
- for n in players:
- # TODO: it doesn't make sense to perform the action on *all* the players!
- # find a sensible criterion to choose the "best one"
- sb.get_object(n, '/org/mpris/MediaPlayer2').__getattr__(ActionMappings[action])()
- if __name__ == '__main__':
- # DBUS boilerplate
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
- sb = dbus.SessionBus()
- # Get the media keys notificator object
- mediaKeysObj = sb.get_object(MediaKeysObjName, MediaKeysObjectPath)
- # Register to receive media keys notifications
- mediaKeysObj.GrabMediaPlayerKeys(app_name, 0, dbus_interface=MediaKeysInterface)
- mediaKeysObj.connect_to_signal('MediaPlayerKeyPressed', onMediaKeyPress)
- # Start the main loop
- mainLoop = gobject.MainLoop()
- mainLoop.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement