hi all, how to play a video in jme3 program ? I hope you can give me a simple example, or other way to implement it, thank you for your sharing.
You’re going to use Java Media Foundation (or it’s extension, Free Media for Java). Note that although FMJ hasn’t an updated build since 2007, you’re going to need to apply it’s patches before you can get fully functional directShow support in Windows.
Limewire had in it’s libraries an updated FMJ, you can try get it’s source code (it’s still on the net) and use it. But beware this isn’t a simple task, so you have a long way to go.
Theres video support for vorbis video in jME3, the test class is actually inside the sources because its not quite done yet.
Well, i’d suggest you use FMJ. I’m actually using it and works well with all formats once you’ve got it configured properly.
I would suggest you start looking at ejmf examples because sample code it’s pretty intuitive, you have only to get it to run properly, but once you’ve got that (note, this should be for “advanced?” users, if you want to call that way) it’s easy to continue.
Anyways if you’re looking for simple video playback then you should use the helper class, it might be easier.
yushir said:
Well, i'd suggest you use FMJ.
Yeah, you did that already but he was asking about "how to play video in jME3". As you said, FMJ hasn't been updated for ages, it doesnt work well on MacOSX and we need testers for the video playback features of jME3 which will be further extended in the future.
Might i say that it currently works fine in OS X. In fact, even a simple wrapper for native libraries would go fine, because in OS X if there’s no wrapper for that format (ie, the player couldn’t be realized) it always fallback to native QT so that video will play if the user has the needed libraries.
Anyways, you have reason. He’s not looking for this, just giving an alternative :).
I recommend the native video playback features in jme3. Well done on video support in jme3 - very happy that it seems to be better supported than the fobs stuff I used in jme2. I’m porting a multi-touch framework over to jme3 - successfully got video items working in the space of a few minutes.
I’d love to be able to have ~3 different (small) videos simultaneously playing. I could do this with jme2 + fobs.
Was/is there a design choice that only ever one video will be played simultaneously in jme3? I notice a single video plays superbly well. More than one video (even small ones) do not play well together.
Cheers.
No, the system will play multiple videos hopefully w/o problems in the future. What exactly do you mean by “do not play well”?
I created VideoPlayer (extends Picture) that encapsulates the video playing code from TestVideoPlayer (see below). I create two or more of these VideoPlayers, testing with a local copy of Sintel_movie_340x144.ogv. Playing just one is fine; playing more than one yields significant delays in all on-screen videos. I’m testing with a MacBook Pro with GeForce GT 330M. Has anybody else tried with more than video at once?
[java]
public class VideoPlayer extends Picture {
private AVThread decoder;
private Thread videoThread;
private VQueue videoQueue;
private long lastFrameTime = 0;
private Clock masterClock;
private AudioNode source;
private float waitTime = 0;
private VFrame frameToDraw = null;
private AssetManager assetManager;
private Renderer renderer;
private AudioRenderer audioRenderer;
public VideoPlayer(String string, boolean b, AssetManager assetManager, Renderer renderer, AudioRenderer ar) {
super(string, b);
this.assetManager = assetManager;
this.renderer = renderer;
this.audioRenderer = ar;
}
public void createVideo(String resource){
try {
InputStream fis = new FileInputStream(resource);
videoQueue = new VQueue(5);
decoder = new AVThread(fis, videoQueue);
videoThread = new Thread(decoder, “Jheora Video Decoder”);
videoThread.setDaemon(true);
videoThread.start();
masterClock = decoder.getMasterClock();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void drawFrame(VFrame frame){
frame.setImage(frame.getImage());
setTexture(assetManager, frame, false);
// note: this forces renderer to upload frame immediately,
// since it is going to be returned to the video queue pool
// it could be used again.
renderer.setTexture(0, frame);
videoQueue.returnFrame(frame);
lastFrameTime = frame.getTime();
}
private void waitNanos(long time){
long millis = (long) (time / Clock.MILLIS_TO_NANOS);
int nanos = (int) (time - (millis * Clock.MILLIS_TO_NANOS));
try {
Thread.sleep(millis, nanos);
}catch (InterruptedException ex){
// stop();
return;
}
}
public void simpleUpdate(float tpf) {
if (source == null){
if (decoder.getAudioStream() != null){
source = new AudioNode(decoder.getAudioStream(), null);
source.setPositional(false);
source.setReverbEnabled(false);
audioRenderer.playSource(source);
}else{
// uncomment this statement to be able to play videos
// without audio.
return;
}
}
if (waitTime > 0){
waitTime -= tpf;
if (waitTime > 0)
return;
else{
waitTime = 0;
drawFrame(frameToDraw);
frameToDraw = null;
}
}else{
VFrame frame;
try {
frame = videoQueue.take();
} catch (InterruptedException ex){
//stop();
return;
}
if (frame.getTime() < lastFrameTime){
videoQueue.returnFrame(frame);
return;
}
if (frame.getTime() == -2){
// end of stream
System.out.println(“End of stream”);
//stop();
return;
}
long AV_SYNC_THRESHOLD = 1 * Clock.MILLIS_TO_NANOS;
long delay = frame.getTime() - lastFrameTime;
// delay -= tpf * Clock.SECONDS_TO_NANOS;
long diff = frame.getTime() - masterClock.getTime();
long syncThresh = delay > AV_SYNC_THRESHOLD ? delay : AV_SYNC_THRESHOLD;
// if difference is more than 1 second, synchronize.
if (Math.abs(diff) < Clock.SECONDS_TO_NANOS){
if(diff <= -syncThresh) {
delay = 0;
} else if(diff >= syncThresh) {
delay = 2 * delay;
}
}
// delay = diff;
if (delay > 0){
waitNanos(delay);
drawFrame(frame);
// waitTime = (float) ((double) delay / Clock.SECONDS_TO_NANOS);
// frameToDraw = frame;
}else{
videoQueue.returnFrame(frame);
lastFrameTime = frame.getTime();
}
}
}
}
[/java]
Maybe the issue is that you are using the same video file for the 3 players. have you tried with different ones?
I wouldn’t recommend using this video playback system, if its not urgent that you support this feature. I am actually working on a new one right now that will be much more stable.
Hi,
I’m trying to play a video clip with jme3!
I’ve found some code examples but I need com.jme3.video jar.
it would be so nice if you could help me resolving this point.
thx…
jme VideoPlayer is deprecated.
But you can always try to modify it to get it work(i dont checked it).