9

I want to get a list of all media playing. Somewhat like the notification bar shows you. Is there a command to do the same?

enter image description here

Heisenberg
  • 1,676

1 Answers1

16

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'

(Spotify is the player, change that accordingly)

playerctl

Or simply use playerctl:

playerctl status
playerctl metadata

Install with apt:

sudo apt install playerctl

Python's D-Bus module

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)

Pablo Bianchi
  • 17,371
pLumo
  • 27,991