Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

how to control VLC by java

I want to run a program called VLC in java and control it while running, for example if user clicked on ?? or ?? button, I do a specific suitable action.

I run VLC by this code :

try
{
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(VLCProgramAddFile + " udp://@:" + listeningPort);

    OutputStream out = p.getOutputStream();
    InputStream in = p.getInputStream();

    p.waitFor();
    System.out.println("End of VLC");
}
catch (Exception e)
{
    System.out.println("error in running VLC");
}

I have heard about Java bindings, but I don't know how does it work for this job.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

VLCj is what you're after yes - it's essentially a straight Java wrapper around libvlc. If you use it in process (especially if you use multiple players in process) you will sometimes see VM crashes - this isn't VLCJ's fault, rather libvlc and the native libraries it uses underneath have some subtle threading bugs that exposes these problems.

You can get it working reliably with multiple instances, but to do so you need to use it out of process. See here for my initial attempts at doing so. It's a bit of work to set up but once going, things seem to work very nicely.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...