From VideoLAN Wiki
Revision as of 04:01, 19 March 2019 by DoesItReallyMatter (talk | contribs) (Edit code: grep -Fq will be faster. Notice the actions are flipped)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
See also: DBus and DBus-spec

The following is a usage example of how to control VLC though DBUS, by simple using dbus-send. This bash script toggles between Play/Pause:

Stopped -> Play

Playing -> Pause

Pause -> Play

if dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep -Fq "int32 2"; then
        # Match found
    	dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
        # Match not found
        dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause

If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause

qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause