Saturday, March 17, 2012

Controlling VLC

After fixing the issue of volume control, now I wanted to be able to use my multimedia keys to play/pause VLC. To do that, I used VLC telnet interface and telnetlib which is a very useful library almost equivalent to the Python library of the same name. Of course, I finally learned that I can use VLC's global hotkeys to achieve this, without the problems I encountered, but I'm gonna post what I came up with just for future reference.

Using telnetlib is very straightforward. The code is pretty self-explanatory.
;; vlc control. vlc telnet interface should be enabled.
(defcommand vlc-play () ()
  "start/resume vlc playback"
  (telnetlib:with-telnet-session (tn "localhost" 4212)
    (telnetlib:read-until tn "Password: ")
    (telnetlib:write-ln tn "admin")
    (telnetlib:read-until tn "> ")
    (telnetlib:write-ln tn "play")
    (telnetlib:read-until tn "> ")
    (telnetlib:write-ln tn "quit")))

(defcommand vlc-pause () ()
  "pause vlc playback"
  (telnetlib:with-telnet-session (tn "localhost" 4212)
    (telnetlib:read-until tn "Password: ")
    (telnetlib:write-ln tn "admin")
    (telnetlib:read-until tn "> ")
    (telnetlib:write-ln tn "pause")
    (telnetlib:read-until tn "> ")
    (telnetlib:write-ln tn "quit")))
Obviously, VLC's telnet interface should be active. I found no way to find out if playback is paused in VLC or not. There are two commands that looked like they should help, but they don't. Telnet command is_playing only returns 0 if playback is stopped, not paused. status command for some reason always says "( state paused )". Anyway, I'm glad that VLC itself can create global key-bindings, so I'm happy with my current situation.

No comments:

Post a Comment

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...