2010-02-18 14 views
5

Ya he visto este hilo, pero sigo teniendo un problema: starting vlc player in java Parece que los enlaces de Java para VLC ya no están en desarrollo activo y no admiten todo posible en la línea de comando de todos modos.Inicie VLC en Java y conéctese a través de la interfaz rc

Dado el siguiente código, no puedo iniciar VLC desde una aplicación Java en Mac OS 10.5.8 (Java 1.6) y luego conectarme a través de la interfaz rc a través del Terminal u otra aplicación Java.

public class Main { 

public static void main(String[] args) { 
    String s = null; 


    try { 
     //Process p = Runtime.getRuntime().exec("/Applications/VLC.app/Contents/MacOS/VLC -I telnet --telnet-host=localhost:4442 -I rc --rc-host=localhost:4444"); 
     //Process p = Runtime.getRuntime().exec("/Applications/VLC.app/Contents/MacOS/VLC -I rc --rc-host=localhost:4444"); 

     //ProcessBuilder pb = new ProcessBuilder("/Applications/VLC.app/Contents/MacOS/VLC","-I rc","--rc-host=localhost:4444"); 
     ProcessBuilder pb = new ProcessBuilder("/Applications/VLC.app/Contents/MacOS/VLC","-IRC","--rc-host=localhost:4444"); 
     Process p = pb.start(); 

     StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), false); 
     StreamGobbler inputGobbler = new StreamGobbler(p.getInputStream(), false); 
     errorGobbler.start(); 
     inputGobbler.start(); 

     System.out.println("Waiting: \n"+p.waitFor());  
     System.out.println("All done here"); 
     //p.destroy(); 
     //System.exit(0); 

    } catch (IOException ioe) { 
    ioe.printStackTrace(); 
    } catch (Exception ie) { 
    ie.printStackTrace(); 
    } 
} 
} 

class StreamGobbler extends Thread { 
InputStream is; 
boolean discard; 
StreamGobbler(InputStream is, boolean discard) { 
    this.is = is; 
    this.discard = discard; 
} 
public void run() { 
try { 
    InputStreamReader isr = new InputStreamReader(is); 
    BufferedReader br = new BufferedReader(isr); 
    String line=null; 
    while ((line = br.readLine()) != null) 
    if(!discard) 
     System.out.println(line);  
    } 
catch (IOException ioe) { 
    ioe.printStackTrace(); 
} 

}}

Aquí es la aplicación Java utilizando el paquete de Apache Commons Net que estoy intentando conectar con la aplicación anterior se ejecuta en la misma máquina:

public class TelnetTest { 
public static void main(String args[]) { 


    TelnetClient tl = new TelnetClient(); 
    try { 
     tl.connect("localhost", 4444); 
     if(tl.isConnected()) { 
      System.out.println("Connected successfully!"); 

      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(tl.getOutputStream())); 
      bw.write("quit"); 
      bw.flush(); 

     } else { 
      System.err.println("Problem with connection"); 
     } 
    } catch(Exception e) { 
     System.err.println("Telnet connection threw an exception: "+e.getMessage()); 
    } 
} 
} 

El esta última aplicación funciona bien si comienzo VLC usando los comandos de la primera aplicación en la Terminal. Del mismo modo, no puedo conectarme a la primera aplicación desde la Terminal usando "telnet localhost 4444" en la Terminal.

La única diferencia que puedo encontrar es en la salida de VLC. Cuando se ejecuta en el terminal:

[0x2786e8] main interface error: no interface module matched "globalhotkeys,none" 
[0x2786e8] main interface error: no suitable interface module 
[0x201b28] main libvlc error: interface "globalhotkeys,none" initialization failed 
Remote control interface initialized. Type `help' for help. 

Cuando se ejecuta a través de la aplicación de la parte superior de Java:

[0x4009178] main interface error: no interface module matched "globalhotkeys,none" 
[0x4009178] main interface error: no suitable interface module 
[0x2017a8] main libvlc error: interface "globalhotkeys,none" initialization failed 
[0x4009178] main interface error: no suitable interface module 
[0x2017a8] main libvlc error: interface "default" initialization failed 

¿Puede alguien ayudarme aquí? Estoy perdido Muchas gracias.

Respuesta

5

Puede ejecutar VLC como un subproceso y alimentarlo a través de la secuencia de salida del proceso. Debe enjuagar la corriente y dormir un rato después de cada comando. El siguiente código no hace todo, pero me permite reproducir archivos diferentes en VLC bajo el control de Java.

 String vlcParameters = String.format(
      "-I rc --rc-fake-tty --video-on-top --disable-screensaver --no-video-title-show " + 
      "--no-mouse-events --no-keyboard-events --no-fullscreen --no-video-deco " + 
      "--x11-display \"%s\" --video-x %d --video-y %d --width %d --height %d", 
      ":0.0", // X11 display 
      top,  // X 
      left,  //Y 
      width, //Width 
      height  //Height 
      ); 

    ProcessBuilder pb = new ProcessBuilder("vlc", vlcParameters); 

    pb.redirectErrorStream(true); 

    vlcProcess = pb.start(); 

// Later - clear current playlist 

     writer.write("clear\n".getBytes()); 
     writer.flush(); 
     Thread.sleep(10); 

     String playListCommand = String.format(
       "add file://%s\n", 
       filePath); 

     writer.write(playListCommand.getBytes()); 
     writer.flush(); 

     Thread.sleep(milliDuration - 10); 

Nota - necesitará otro hilo para leer la salida de VLC para que no se bloquee:

 Thread inputThread = new Thread(new Runnable() 
     { 

     @Override 
     public void run() 
      { 
      InputStream in = vlcProcess.getInputStream(); 

      BufferedReader bufin = new BufferedReader(new InputStreamReader(in)); 

      try 
       { 
       while (true) 
       { 
       String line = bufin.readLine(); 

       if (line == null) 
        { 
        System.out.writeln("End of data from VLC"); 
        } 

       System.out.writeln("VLC OUTPUT:" + line); 
       } 
       } 
      catch (IOException ex) 
       { 
       //... 
       } 
      } 
     }, 
     "VLC stdout reader"); 

    inputThread.start(); 
+0

Para cualquiera que desee implementar esto, tenga en cuenta el "\ n" al final de cada comando. También tenga en cuenta que el cierre de la secuencia de salida hará que la instancia de VLC se cierre. Estas fueron dos cosas que me sorprendieron. –

0

Desde VLC abre una nueva ventana de DOS en modo RC, durante writer.flush () el código se queja de que la tubería estaba cerrada. esto también se verificó cuando el inputThread imprime "VLC OUTPUT: null Fin de los datos de VLC". ¿Hay alguna forma de evitarlo, vincular a la ventana vlc rc recién abierta?

Saludos

Shahid

Cuestiones relacionadas