在Java中启动VLC并通过rc接口连接到它
我已经看过这个帖子,但仍然遇到问题: 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
有人可以帮我吗?我不知所措。非常感谢。
I've already seen this thread, but I'm still having an issue: starting vlc player in java It appears the Java bindings for VLC are no longer under active development and do not support everything possible on the command line anyway.
Given the following code, I can't launch VLC from a Java application on Mac OS 10.5.8 (Java 1.6) and then connect to it via the rc interface through the Terminal or another Java application.
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();
}
}
}
Here is the Java application using the Apache Commons Net package that I'm trying to connect to the above app running on the same machine:
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());
}
}
}
The latter app works fine if I start VLC using the commands from the first app in the Terminal. Likewise, I can't connect to the first app from the Terminal using "telnet localhost 4444" in the Terminal.
The only difference I can find is in the output from VLC. When running in the 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.
When executing via the top Java application:
[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
Can anyone help me out here? I'm at a loss. Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 VLC 作为子进程运行,并通过进程输出流向其提供命令。您需要在每个命令后刷新流并休眠一会儿。下面的代码
并不能完成所有事情 - 但它确实允许我在 Java 的控制下在 VLC 中播放不同的文件。
注意 - 您将需要另一个线程来读取 VLC 的输出,这样它就不会阻塞:
You can run VLC as a subprocess and feed it commands through the process output stream. You need to flush the stream and sleep for a little while after each command. The following code
doesn't do everything - but it does allow me to play different files in VLC under control of Java.
Note - you will need another thread to read the output from VLC so it doesn't block:
在另一个论坛上找到了解决方案: http://forums.sun.com/thread.jspa ?threadID=5145675
显然,在 Linux 或 Mac 下运行时,您必须将“--rc-fake-tty”参数传递给 VLC。
Found the solution on another forum: http://forums.sun.com/thread.jspa?threadID=5145675
You have to pass the "--rc-fake-tty" argument to VLC when running under Linux or Mac apparently.
由于 vlc 在 rc 模式下打开一个新的 DOS 窗口,因此在 writer.flush() 期间,代码抱怨管道已关闭。这也得到了验证,因为 inputThread 打印“VLC OUTPUT:nullEnd of data from VLC”。有没有办法避免它,链接到新打开的 vlc rc 窗口?
问候
沙希德
Since vlc opens a new DOS window in rc mode, during writer.flush() the code complains that the pipe was closed. this was also verified as the inputThread prints "VLC OUTPUT:nullEnd of data from VLC". Is there a way to avoid it, to link to the newly opened vlc rc window?
Regards
Shahid