Difference between revisions of "DBus-usage"

From VideoLAN Wiki
Jump to navigation Jump to search
m (syntaxhighlight, see also: DBus)
Line 1: Line 1:
 +
{{See also|DBus|DBus-spec}}
 +
 
The following is a usage example of how to control VLC though DBUS, by simple using dbus-send.
 
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:
 
This bash script toggles between Play/Pause:
Line 8: Line 10:
 
Pause -> Play
 
Pause -> Play
  
<pre>
+
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 
if [ -z `dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep "int32 2"` ]; then
 
if [ -z `dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep "int32 2"` ]; then
Line 15: Line 17:
 
     dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
 
     dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
 
fi
 
fi
</pre>
+
</syntaxhighlight>
  
 
If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause
 
If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause
  
<pre>
+
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
 
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
</pre>
+
</syntaxhighlight>
 
 
== See also ==
 
* [[DBus-spec]]
 
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 03:22, 19 March 2019

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

#!/bin/bash
if [ -z `dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep "int32 2"` ]; then
        dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause
else
    	dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
fi

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

#!/bin/bash
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause