Controlling VLC from Elsewhere
Outcome: VLC answers to a web browser — behind a password — reporting what it is playing and taking orders; and it answers to a typed prompt that a script can drive. Both run for real in this chapter.
An interface is a rider (chapter 2), so a VLC playing in one room can take orders from another. Two riders come built in, and the lab ran both.
The HTTP interface: a web page that drives
Start VLC with the HTTP interface enabled, an address, and a password — in the lab, on the same assigned port the streaming chapter used, playing the fixture tone on loop:
cvlc -I dummy --extraintf http \
--http-host=127.0.0.1 --http-port=18091 \
--http-password=fixturepass \
--loop tone.flac
(--http-host, --http-port and
--http-password are the interface's
own options, from the advanced help
in transcript t09.) The password is
not decoration; the lab checked the
door both ways (transcript t06):
$ curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:18091/
401
$ curl -s -u :fixturepass http://127.0.0.1:18091/requests/status.xml
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<root>
<state>playing</state>
<version>3.0.20 Vetinari</version>
<time>3</time> <length>8</length>
<info name='title'>Fixture Tone</info>
<info name='artist'>VLC Lab</info>
...
</root>
401 without the password — the
interface refuses strangers. With it,
the status document tells the whole
story of the moment: the player is
playing, 3 seconds into an 8-second
file whose title and artist it reports
from the file's tags, and the answer
also carries the running statistics —
packets read, audio buffers decoded
and played, bytes through the demuxer.
Appending a command to the same address
gives orders: ?command=pl_pause
pauses; ?command=in_play&input=...
plays something else; the commands are
a documented family under
/requests/. In a browser, the same
address serves a small web page with
buttons — the pocket remote for a
player across the room.
The password is the whole fence.
The HTTP interface can order the
player to play any file the machine
can read, which is a great deal of
power to leave on a network; the lab
ran it on 127.0.0.1, reachable only
from its own machine, and so should
you until you have decided exactly who
may drive. Never expose it to the
internet with a weak password, or
without one — the interface itself has
no second factor and no lockout.
One lab finding belongs here rather
than in a footnote: the volume order
(?command=volume&val=100) was
accepted without complaint, and the
status afterwards still reported
<volume>0</volume>. The lab's player
was playing into the dummy audio
output, which has no gain to turn —
there was no volume for the order to
land on. With real speakers the same
order lands normally. The lesson
generalises, and chapter 13 repeats
it: when an order silently does
nothing, ask which module was
supposed to carry it out.
The RC interface: a prompt for scripts
The older rider is a typed prompt:
cvlc -I rc --vout=dummy --aout=dummy
The lab drove it from a script —
commands written to its input on a
schedule (transcript t07):
> add .../tone.flac
> get_time
1
> get_length
8
> quit
Shutting down.
get_length answers 8: the
fixture's eight seconds, counted by
the player itself. The command family
covers the whole transport (play,
pause, seek, stop), the playlist
(add, enqueue, playlist), and
information (info, get_time,
get_length, stats — the same
statistics the web status carries).
Because the prompt reads plain lines
from standard input, anything that can
print lines can drive a player: a shell
script, a scheduler, a home-automation
rule. Between the two riders, the rule
of thumb is: HTTP for people and
dashboards, RC for scripts on the same
machine.