【发布时间】:2011-01-18 04:45:00
【问题描述】:
我已经看过这个帖子,但我仍然有一个问题:starting vlc player in java VLC 的 Java 绑定似乎不再处于积极开发中,并且无论如何都不支持命令行上的所有可能。
鉴于以下代码,我无法从 Mac OS 10.5.8 (Java 1.6) 上的 Java 应用程序启动 VLC,然后通过终端或其他 Java 应用程序通过 rc 接口连接到它。
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();
}
} }
这是使用 Apache Commons Net 包的 Java 应用程序,我试图连接到在同一台机器上运行的上述应用程序:
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());
}
}
}
如果我使用终端中第一个应用程序的命令启动 VLC,后一个应用程序可以正常工作。同样,我无法使用终端中的“telnet localhost 4444”从终端连接到第一个应用程序。
我能找到的唯一区别是 VLC 的输出。在终端运行时:
[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.
通过顶级 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
有人可以帮我吗?我不知所措。非常感谢。
【问题讨论】: