That feature s implemented with MPRIS (Media Player Remote Interfacing Specification), a standard D-Bus interface.
D-Bus with dbus-send
You can control it with DBUS commands manually, but I find it "a little bit" complicated for everyday use:
# Get current Status
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
string:'org.mpris.MediaPlayer2.Player' \
string:'PlaybackStatus'
# Get Metadata of currently playing song (if Playing)
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
string:'org.mpris.MediaPlayer2.Player' \
string:'Metadata'
You can also control players with python's dbus module:
#!/usr/bin/env python3
import dbus
bus = dbus.SessionBus()
for service in bus.list_names():
if service.startswith('org.mpris.MediaPlayer2.'):
player = dbus.SessionBus().get_object(service, '/org/mpris/MediaPlayer2')
status=player.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus', dbus_interface='org.freedesktop.DBus.Properties')
print(status)
metadata = player.Get('org.mpris.MediaPlayer2.Player', 'Metadata', dbus_interface='org.freedesktop.DBus.Properties')
print(metadata)
That feature s implemented with
MPRIS
(Media Player Remote Interfacing Specification), a standard D-Bus interface.D-Bus with
dbus-send
You can control it with DBUS commands manually, but I find it "a little bit" complicated for everyday use:
(Spotify is the player, change that accordingly)
playerctl
Or simply use
playerctl
:Install with
apt
:Python's D-Bus module
You can also control players with
python
'sdbus
module: