How to control media player from CLI using D-Bus/MPRIS

  • MPRIS is a standard dbus interface for programmatic control media players any media player
## install
$ sudo apt-get install qtchooser

## using (clementine)
$ show information about the currently playing song
$ qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.GetMetadata
# same but v2
$ qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata
# show all mpris players running
$ qdbus org.mpris.MediaPlayer2.*

# control player
$ qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Pause
$ qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.VolumeSet 50

from MPRIS@clementine

## install
$ sudo apt-get install mpris-remote

## using
# uses that first media player or MPRIS_REMOTE_PLAYER env
$ mpris-remote identity
# shows current player status, song playing
$ mpris-remote
# shows current track info tags
$ mpris-remote trackinfo
# shows corrent player status
$ mpris-remote playstatus

# control player and volume
$ mpris-remote prev|next|play|stop|pause
$ mpris-remote volume 

# populates current playlist
$ mpris-remote clear
$ find ~/music -name '*.mp3' | mpris-remote addtrack -

# eg: bash prompt with media info
function mpris { echo `{ mpris-remote trackinfo && mpris-remote playstatus; } | sed -n -r 's,'$1': (.*),\1,p'`; }
export PS1_old="$PS1"
export PS1="\$(mpris playing) \$(mpris title)\n$PS1_old"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s