13

Is there a way to manipulate VLC with a Linux shell script without the script waiting for VLC to close.

cvlc test.mp3
echo "Now playing!"
sleep 200
cvlc://pause:60

This code keeps running VLC until the file is completed, and then evidently it is to late to pause the file.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555

3 Answers3

18

You need to use dbus interface of VLC.

enter image description here

Now, you can use the mpris interface of VLC. It's a standard for most players like clementine, banshee, songbird, spotify etc.

So, lets suppose you want to Pause the currently playing song.

dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause

To play a song:

dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play

I generally use qdbusviewer to know about the dbus-interface available to me.

shadyabhi
  • 16,675
  • 26
  • 80
  • 131
  • 5
    Although your solution pointed me in the right direction, current VLC only accepts a slightly different implementation. For example: `dbus-send --session --type=method_call --print-reply --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause` – Adam Eberlin Sep 23 '12 at 18:22
  • Cool. Glad that my answer was of help. – shadyabhi Sep 24 '12 at 06:18
  • Thanks for mentioning qdbusviewer. – exic Dec 02 '14 at 11:50
  • 1
    May be a little late, but, I'll leave it here for reference. This bash script uses gdbus to do various operations with a running instance of vlc, like, get supported mime types, get status, play, pause, get / set volume, list instances, etc.: https://gist.github.com/amol9/6d47fdd21a1c5e006c84 – Amol Jan 17 '16 at 14:35
4

Dbus is one way but dbus does not exist on all systems. The more common method would be to use the rc interface:

cvlc -I rc --rc-host localhost:11337 -d

Then one can use netcat to pipe commands into the tcp socket. For example:

vlc -I rc --rc-host localhost:11337 test.mp3 -d &
echo "Now playing!"
sleep 200
echo pause | netcat localhost 11337

EDIT:

After testing with a few other interfaces I have discovered the oldrc interface accepts UNIX domain sockets thus the following will work as well with out needing to play around with firewalls or worry about anyone else on the network messing around with your vlc instance.

vlc -I oldrc --rc-unix /var/run/vlc.sock -d
echo "Now Playing!"
sleep 200
echo "pause" | netcat -U /var/run/vlc.sock
Dwight Spencer
  • 1,472
  • 16
  • 22
2

It looks like you can redirect from standard input or a named pipe. For more complicated things you could use libvlc.

http://wiki.videolan.org/Uncommon_uses

Jeff M
  • 101
  • 1
  • 3