Created
March 16, 2021 15:30
-
-
Save tormath1/f547233ad902986ca5aa81385e2c814d to your computer and use it in GitHub Desktop.
Play / Pause your Chromium multimedia using d-bus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # goal of this script is to control (play / pause) multimedia played | |
| # on a chromium tab through dbus | |
| # requirements: | |
| # * dbus (session) | |
| import dbus | |
| # used to identify a Dbus chromium instance | |
| CHROMIUM_INSTANCE_PATTERN = "org.mpris.MediaPlayer2.chromium" | |
| session = dbus.SessionBus() | |
| # we first need to find out the "instance" of chromium we want to control | |
| dbus = session.get_object( | |
| "org.freedesktop.DBus", | |
| "/org/freedesktop/DBus", | |
| ) | |
| names = dbus.ListNames() | |
| for name in names: | |
| if not CHROMIUM_INSTANCE_PATTERN in name: | |
| continue | |
| mpris = session.get_object( | |
| name, | |
| "/org/mpris/MediaPlayer2", | |
| ) | |
| mpris.PlayPause(dbus_interface="org.mpris.MediaPlayer2.Player") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment