Tôi đã thấy chủ đề này, nhưng tôi vẫn gặp sự cố: starting vlc player in java Dường như các ràng buộc Java cho VLC không còn hoạt động và không hỗ trợ mọi thứ có thể trên dòng lệnh anyway.Khởi chạy VLC trong Java và kết nối với nó qua giao diện rc
Với mã sau, tôi không thể khởi chạy VLC từ một ứng dụng Java trên Mac OS 10.5.8 (Java 1.6) và sau đó kết nối với nó thông qua giao diện rc thông qua Terminal hoặc một ứng dụng Java khác.
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();
}
}}
Đây là ứng dụng Java bằng cách sử dụng gói Net Apache Commons mà tôi đang cố gắng để kết nối với các ứng dụng trên chạy trên cùng một máy:
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());
}
}
}
Các sau này ứng dụng hoạt động tốt nếu tôi bắt đầu VLC bằng cách sử dụng các lệnh từ ứng dụng đầu tiên trong Terminal. Tương tự như vậy, tôi không thể kết nối với ứng dụng đầu tiên từ Terminal bằng cách sử dụng "telnet localhost 4444" trong Terminal.
Sự khác biệt duy nhất tôi có thể tìm thấy là ở đầu ra từ VLC. Khi chạy trong 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.
Khi thực hiện thông qua các ứng dụng Java trên:
[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
bất cứ ai có thể giúp tôi ra ở đây? Tôi đang thua lỗ. Cảm ơn nhiều.
Để bất cứ ai muốn thực hiện điều này, lưu ý các "\ n" ở cuối mỗi lệnh. Cũng lưu ý rằng việc đóng luồng đầu ra sẽ làm cho cá thể VLC tắt. Đây là hai thứ khiến tôi hiểu. –