VLC and Java pipeing

I am currently really confused about why my program doesn’t work.
Here I have set up a tiny test program for you:


public static void main(String[] args) {
	try {
		// Start new Process / Start VLC:
		Process p = Runtime.getRuntime().exec(new String[] { "vlc", "-vvv" /* Super-verbose*/});
		BufferedReader read = new BufferedReader(new InputStreamReader(p.getInputStream()));
		String line;
		while ((line = read.readLine()) != null) {
			System.out.println("VLC has print: " + line);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}

Try starting “vlc -vvv” via command line too. You will see lots of debug-text, which is what I need.

Tangential question - what are you actually trying to do, and why not use https://github.com/caprica/vlcj?

You can use my code as reference:

http://pastebin.java-gaming.org/54a6b2d341c

Okey. Sorry for spawining such a topic… I “fixed” it…
I used a “workaround”.

I’m using gstreamer now :smiley: (over commandline via “gst-launch-0.10 playbin2 …”).
Works fine, and even does return if the song is finished.

For the sake of the community, share your code! :slight_smile:

Was actually for private use, because I hated all these hard-to-use and take-10-years-to-“learn”-players, so I invented my own one.

The player is super simple. It just searches recursivly through the current directory, the jar is placed in, and then just picks a random one, and plays it. Remember, this is a commandline tool. Don’t expect to get some windows popped up. I like commandline tools, because it is so simple, and I have a konsole opened with one key: F12 (install yakuake :wink: ). The only available things to tell the player are: “next” and “exit”. Exit will make the player exit, and “next” will make the player pick the next song.

So finally, here is the source:
http://pastebin.java-gaming.org/54a6b6d341c

Have fun :wink: (also, this is programmed in about 1h now ;D

EDIT: I forgot. Make sure you have all gstreamer plugins installed, especially the mp3-player plugin :wink: (this player only plays .mp3)

Thanks!

p = Runtime.getRuntime().exec(commands);

If the process writes a significant amount of bytes to either stdout or stderr, it will eventually block if you don’t read these streams from the Java side.

What would be the fix, or the workaround? Reading that InputStream, doing nothing with it?


public static void asyncConsumeStream(final InputStream in) {
   new Thread(new Runnable() {
      public void run() {
         consumeStream(in);
      }
   }).start();
}

public static void consumeStream(InputStream in) {
   byte[] tmp = new byte[4*1024];
   try {
      while(in.read(tmp) != -1) {
         continue;
      }
      in.close();
   }
   catch(IOException exc) {
      // ignore
   }
}
asyncConsumeStream(p.getInputStream()); // stdout
asyncConsumeStream(p.getErrorStream()); // stderr

thanks a lot :slight_smile:
Fixed an issue on another project I have :smiley:

Hi

Matheus23, why don’t you use com.jogamp.opengl.util.av.GLMediaPlayerFactory to do that? If you need some help, let us know. Sorry for the “off topic”.

Just got to point out that VLCJ is GPL, which means that you’ll have to release all source code you write, if you use it. And it won’t be changed to LGPL like libVLC and libVLCcore is. I know this because I mailed him asking if he’d release it under another license.

He was still undecided when I asked him 2 months ago or so. What did he say exactly ?
Well if it really comes to this I am just going to GPL my code. Its not like anyone cares about source code anyway; and maybe I can even only make a certain part GPL that interacts with VLCJ…

6 days ago.

Here is his email:

I guess he isn’t saying that it’ll never be LGPL, but… :stuck_out_tongue:

well fine
I would even pay money for a good video playback lib - but obviously not too much
but GPL isnt that bad - end user dont care either way

what is weird is: he couldnt even answer me back then if it was possible to only GPL a part of my source code that uses VLCJ and stuff, since he is not a lawyer, he said.
But I dont get why he likes and wants GPL, if he doesnt even understand it completely. What are his benefits =o

Almost certainly not, as that would be breaking the license conditions, unless you went with weird hacks in terms of how you distribute, and even that would be dubious.

GPL’s a great license if you have control of the code base, as it gives you better leverage to commercialise your code. I assume if he’s bothered he might be making (or envisages making) money from commercial licensing.

What’s wrong with GStreamer? That’s LGPL (apart from a couple of optional codecs) and works great.

Guy, we talked about this in great length in various threads… we had some success with vlcj, I dont recall anyone who produced what we need with gstreamer. it might be possible, but I think no one but you looked into gstreamer that long.

we need theora/vorbis playback, in opengl meaning it will have to render it to an LWJGL texture.
the game you are distributing has to work on all 3 platforms
it has to have everything the game needs to play the video
the user cannot be promted to install anything, not gstreamer, not vlc - its all packaged
it has to just work, even on weaker machines, as best as possible, no audio/video desync and no tearing if possible

I pretty much got it with VLCJ, just the license makes a little trouble

if you can release a lwjgl example that plays a theora video, with everything bundled, which just works on all platforms, then I would take gstreamer seriously
When trying I couldnt get the linking to work
with vlc I just have a “vlib” folder, put everything there and tell VLCJ to look there.

He actually sells a commercial license via his website, so I guess he gets money from it. xD

I would really be interested how much that would be.

I’m aware we’ve discussed before, and I’ve also told you that Praxis does almost all this already (not doing audio playback at the moment for other reasons). That includes bundling GStreamer, and rendering into an LWJGL texture. My GStreamer plugin for Windows may be an optional download, but it could as easily work bundled - it’s all locally linked. However, Praxis is a far bigger project than you need for this. As I’ve said, I’ll point you in the right direction with what’s in the Praxis plugin to make this work, but I’m not writing it. It’s a simplified fork of what’s in Processing anyway. There’s some code up here (theagentd?) that will directly push the data to a texture in a much simpler way than my code.