Controlling VLC media player using JAVA


VLC Media Player

Basically, I was looking for a method to communicate with the VLC media player so that I can get the currently playing video on the player and my app can search the internet and get the details about the movie. For that, I googled a lot and finally came to know that VLC has a web interface and I used that with my JAVA app to control and getting details of the movie.



Setting Up

First, open the VLC and go to tools->preferences and check the All radio button. and navigate to the Main Interface and click on lua and there you have to set HTTP password (Otherwise u cannot access the web interface). The screenshot is given below.   

Now lets clear some security issues on windows to allow us to control the VLC from any PC in the network. Goto Control Panel click on Allow a program through Windows Firewall.

And now click allow another program and browse to VLC.exe and check on as shown below.

Now open any browser and navigate to  you will see an interface as below. Before that in VLC player set the web interface on. That’s it now you can control the Player from the browser. Now comes the JAVA Part.

package com.oksbwn.Y2014.vlcInteraction;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class vlcStatus {
  String time;
  String name;
  String state;
  String length;
  public static void main(String[] args) {
    vlcStatus vs = new vlcStatus();
    replace r = new replace();
    String mov = vs.getName();
  public  vlcStatus() {
    try {
      String urlString = "";
      Authenticator.setDefault(new authoRize());
      URL url = new URL(urlString);
      InputStream content = (InputStream) url.getContent();

      DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
      DocumentBuilder b = f.newDocumentBuilder();
      Document doc = b.parse(content);
      // loop through each item
      NodeList items = doc.getElementsByTagName("root");
      Element e = (Element) items.item(0);

      time = e.getElementsByTagName("time").item(0).getChildNodes().item(0).getNodeValue();
      length = e.getElementsByTagName("length").item(0).getChildNodes().item(0).getNodeValue();
      state = e.getElementsByTagName("state").item(0).getChildNodes().item(0).getNodeValue();

      NodeList items1 = e.getElementsByTagName("information");
      Element f1 = (Element) items1.item(0);

      NodeList items11 = f1.getElementsByTagName("category");
      Element f111 = (Element) items11.item(0);
      try {
        name = f111.getElementsByTagName("info").item(2).getChildNodes().item(0).getNodeValue();
      } catch (Exception e1) {

        try {
          name = f111.getElementsByTagName("info").item(1).getChildNodes().item(0).getNodeValue();
        } catch (Exception e11) {
          try {
            name = f111.getElementsByTagName("info").item(0).getChildNodes().item(0).getNodeValue();
          } catch (Exception e2) {
            try {
              name = "oksbwn";
            } catch (Exception e111) {}

    } catch (Exception e) { //new handleExceptions(e);

  public String getName() {
  public String getTime() {
    return this.time;
  public String getedState() {
    return this.state;
  public String getLength() {
    return this.length;

And the CODE for the authorization is.

package com.oksbwn.Y2014.vlcInteraction;
class authoRize extends Authenticator {
  private String username, password;

  public authoRize() {
    username = "";
    password = "om";
  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(username, password.toCharArray());


Leave a Comment