How to control VLC using java

I want to run a program called VLC in java and control it while I work, for example, if the user presses the pause or fast forward button, I perform a specific appropriate action. I start VLC with 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 heard about Java bindings, but I don't know how this works for this job.

+6
java vlc vlcj
source share
3 answers

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

(Note that this is normal for custom applications, but the VLCJ library is not perfect, you may experience several problems.)

EDIT: For my project, I saw memory leaks and problems with lengthy programs (multiple instances over several hours). In particular, multiple instances do not work in conjunction with some compilation options (which are enabled by default).

+5
source share

VLCj is what you after yes is, in fact, the direct Java shell around libvlc. If you use it in the process (especially if you use several players in the process), you will sometimes see VM crashes - this is not a VLCJ error, but libvlc and its own libraries that it uses under them contain some subtle errors in the threads that cause these Problems.

You can make it work reliably with multiple instances, but for this you need to use it outside the process. See here for my initial attempts to do this. This is a little setup work, but as soon as it happens, everything looks very good.

+5
source share

Depending on what you want to accomplish in the long run, maybe gstreamer Java bindings are worth the look that will give you very fine control over playback. And you can do conversions and all that. They also have an example of a minimalistic video player that you started with.

0
source share

All Articles