Skip to content
Advertisement

How to connect to MediaPlayer2.Player PlaybackStatus signal using pygtk?

I actually want to display the information about the media or song currently being played with a window as a popup containing the artwork and the song name etc. I read about that a

PlaybackStatus

signal is emitted whenever a media is playing or stopped. How would i connect to that signal, well I read about dbus and came to know that it can be accessed using the org.freedesktop.DBus.Properties interface. I have recently started development with PyGtk so I don`t know how to do it?

Thanks.

Advertisement

Answer

Before doing this with Python I find it useful to experiment on the command line to see what the expected values are. This can be done with the busctl tool.

The media players are on the Session (or user) bus.

JavaScript

I can use the name of the service to find the objects in the D-Bus tree:

JavaScript

With the name and the object path the object can be introspected

JavaScript

As you want to use Gtk it would seem sensible to use the D-Bus binding from https://pygobject.readthedocs.io/en/latest/

It will mainly be the DBusProxy that will be required.

An example of a window with a couple of labels for playback status and artist information might look like the following:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement