开发者

how to control VLC by java

开发者 https://www.devze.com 2023-01-17 07:14 出处:网络
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 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.


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.


You are probably looking for VLCJ, this is a java wrapper for VLC. It allows you to embed VLC media player in a java application, and thus add all your personal controls.

(Do note that for user applications this is fine, but the VLCJ library isn't perfect, you can have several problems pop up.)

EDIT: For my project I've seen memory leaks and issues with long running programs (multiple instances for several hours). Especially the multiple instances doesn't work in combination with some compile options (which are on by default).


Depending on what you want to ultimately accomplish maybe the gstreamer Java bindings are worth a look which will give you a very fine grained control about the playback. And you can do conversions and everything. They also have a minimalistic video player example application to get you started with.

0

精彩评论

暂无评论...
验证码 换一张
取 消