I'm sure there's a nice, clean way of doing this. Probably via D-bus. Sadly, I don't know what that way is so here's a more hacky approach. You can use
lsof to print the files opened by a running process. The relevant option here is (from
-c c selects the listing of files for processes executing the
command that begins with the characters of c. Multiple commands
may be specified, using multiple -c options. They are joined in
a single ORed set before participating in AND option selection.
lsof -c vlc will list all files opened by processes whose name starts with
vlc. That, however, will list all sorts of stuff, including various libraries and other things we don't care about. The 4th field of
lsof's output (on my Arch, at least) is the file descriptor of the file (for regular files) followed by a single letter describing the mode in which the file has been opened (
r for reading, in this case). The 5th field is the type of file and here, we want that to be
REG for regular. Putting all this together, we get (the
-w suppresses warnings):
$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"'
vlc 16532 terdon 16r REG 8,19 131338 69731703 /path/to/foo.avi
To get only the file name you could use GNU
$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"' | grep -o '/.*'
And to get the file name only:
$ lsof -wc vlc | awk '$4~"[0-9]r" && $5=="REG"' | grep -o '[^/]*$'