Skip to content

Instantly share code, notes, and snippets.

@tormath1
Created March 16, 2021 15:30
Show Gist options
  • Save tormath1/f547233ad902986ca5aa81385e2c814d to your computer and use it in GitHub Desktop.
Save tormath1/f547233ad902986ca5aa81385e2c814d to your computer and use it in GitHub Desktop.
Play / Pause your Chromium multimedia using d-bus
#!/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