Recently I was using VLC to listen to music, as I often do, and I wanted to pause without getting out of bed.
Lazy? Yes!
I learned that VLC includes a slew of remote control interfaces, including a built-in web interface as well as a raw socket interface.
In VLC Advanced Preferences, go to “Interface”, and then “Main interfaces” for a list of options. I selected “Remote control” which is now known as “oldrc”, and I configured a simple file based socket “vlc.sock” in my home directory as an experiment.
You can use netcat to send commands, for example,
twarnock@laptop:~ :) nc -U ~/vlc.sock <<< "pause"
Best of all VLC cleans up after itself and removes the socket file when it closes. The “remote control” interface is pretty intuitive and comes with a “help” command. I wrapped all of this in a shell function (in a .bashrc).
function vlcrc() { SOCK=~/vlc.sock CMD="pause" if [ $# -gt 0 ]; then CMD=$1 fi if [ -S $SOCK ]; then nc -U $SOCK <<< "$CMD" else (>&2 echo "I can't find VLC socket $SOCK") fi }
I like this approach because I can now use “vlc command” in a scripted environment. I can build playlists, control the volume, adjust the playback speed, pretty much anything VLC lets me do. I could even use a crontab and make a scripted alarm clock!
And of course I can “pause” my music from my phone while laying in bed. Granted, there’s apps for more user friendly VLC smartphone remotes, but I like the granular control provided by a command line.