Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/ on line 14
Fotos auf flickr

Auto-pause Rhythmbox on Ubuntu when screensaver goes active :: 7. September 2011, 14:30

I was looking around for a solution to pause Rhythmbox whenever I lock my screen, and to continue playing when I return. Looking around the intarwebs, I found a blog post with a basic Python script.

I changed some aspects of that script to suit my needs, namely:

UPDATE: With Ubuntu 11.10, Rhythmbox changed to the MPRIS interface — I adapted the script accordingly.

So without further ado, here’s my version of it:


import dbus
import dbus.glib 
import gobject

paused = False

def screensaver_changed(state):
	"""This method is called when the screensaver starts/stops """
	global paused
	if session_bus.name_has_owner('org.mpris.MediaPlayer2.rhythmbox'):
		proxy = session_bus.get_object('org.mpris.MediaPlayer2.rhythmbox', '/org/mpris/MediaPlayer2')
		player = dbus.Interface(proxy, 'org.mpris.MediaPlayer2.Player')
		props = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')
		if state and props.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') == "Playing":
			paused = True
		elif not state and paused:
			paused = False

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