UARG! JMF video playback ... does it work in any way!?

There is my simple task on playing any video format, which I am able to encode for free.
So I tried JMF 2.1.1 and Java 6 … but it throws only Exceptions of not supported format, not
supported frame rendering or things like “Unable to realize com.sun.media.PlaybackEngine”
although I really tried to encode in formats. which are given for the cross platform version
given here:

http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/formats.html

So can anyone describe me a way to encode a video (better: to convert an existing one with
a tool) so it is played by JMF? Or is there any (platform independend!) alternative?

well, if it is any format then just “encode” each video frame as an png and then for play back just read in a reasonable buffer of frames and then display them… not elegant but is cross platform independent :stuck_out_tongue:

</cheap shot>

I cannot help you with JMF… perhaps you can attempt to use the native os file association to load your video in the native video player by runing an external process?

Jerry-rigged Media Fcuk-up ;D

I actually got JMF to work one day, with a webcam.

It was so much slower than the native app… 15fps (100% CPU load) vs 60fps (5% CPU load)

That really can not be the actual situation! Uaaargh!
I clearly remember the last time I was active in game development (about erm 6 years ago?). And I knew that
JMF was only a bunch of problems. Now I thought that the media support should have matured enough so that
it would be no problem of rendering a video of a common format in Java!

So do we have to forget about video cutscences in Java games (really?!)?

you can pretty easily use something like VLC Media Player with java, worked pretty well the last time I tried it. (just grab the hwnd and embed into a java app)

JMF is dead.

Have a look at JMC and especially JMediaPane.

Thanks for the replies on alternatives. Can you tell me if the mentioned player components are
platform independend - so no native libraries are used?

VLC Media Player is totally platform dependent :slight_smile:
but it has builds for all the main architects.

Perhaps im searching a bit clumsy … but where can I download the libraries for JMC?

came across this nice article might be worth a read http://www1.siconet.at/Kastna/wordpress/?p=609

That’s great! I always wondered what to use for video on Java ;D

Xiph.org has a pure java implementation of the Theora codec available in a signed jar. It’s royalty free and is playable, but still drops frames, on my crappy laptop.

Cortado

Anyone knows if it is possible to use FOBS to grab the frames of the video. Have been looking for a way to do video textures.

That looks pretty cool!

I couldn’t find any example code on how to integrate it into an application instead of an Applet.

If you go into the git tree there is a directory of examples including one that shows the applet embedded in a frame and manually setting the applet parameters.

Hm, project seems a bit dead - no news since 2008, and no MacOS or Linux binaries for the latest version.

Cas :slight_smile:

JMC is used internally by JavaFX. Download the JavaFX SDK and look for jmc.jar (don’t forget the native library for your platform, jmc.dll, jmc.so or jmc.jnilib).

Look at this to see an example of source code using JMediaPlayer:
http://floris.ouwendijk.nl/blog/index.php?blog=2&title=java_media_components&more=1&c=1&tb=1&pb=1

WOOOHAAA!

Now I can proudly present: A SOLUTION!

First of all thx to all the replies, the solution is indeed to extract the JMC Framework
from JavaFX.

But trying to use the tutorial in the link given by gouessej does not work:
(http://floris.ouwendijk.nl/blog/index.php?blog=2&title=java_media_components&more=1&c=1&tb=1&pb=1)
The problem is, that the posted code relates to JavaFX 1.1, but the actual Version does not support the JMediaPlayer
class anymore.

With a little search I found other, which shared the problem. Indeed you have to grab the jar-libraries and native .dlls
from the JavaFX Installation and do something like this (quick’n’dirty example, please see the original thread in this forum:
http://www.java-forum.org/allgemeine-java-themen/93807-videos-abspielen-etc.html)


package test;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.media.jmc.MediaProvider;
import com.sun.media.jmc.control.VideoRenderControl;
import com.sun.media.jmc.event.VideoRendererEvent;
import com.sun.media.jmc.event.VideoRendererListener;

public class PlayerTest implements VideoRendererListener
{

	private MediaProvider		prov;
	private VideoRenderControl	renderer;
	private Graphics2D			ig;
	private JPanel				panel;

	public PlayerTest(File path, JPanel panel)
	{
		ig = (Graphics2D) panel.getGraphics();
		this.panel = panel;
		prov = new MediaProvider(path.toURI());
		renderer = prov.getControl(VideoRenderControl.class);
		renderer.addVideoRendererListener(this);
		
		prov.play();
	}

	@Override
	public void videoFrameUpdated(VideoRendererEvent arg0)
	{
		float ratio = renderer.getFrameSize().height / (float) renderer.getFrameSize().width;

		int diff = (panel.getHeight() - Math.round(ratio * panel.getHeight())) / 2;

		renderer.paintVideo(ig, new Rectangle(0, 0, renderer.getFrameSize().width,
				renderer.getFrameSize().height), new Rectangle(0, diff, panel.getWidth(), Math.round(ratio
				* panel.getHeight())));

	}

	public static void main(String[] args)
	{
		JFrame frame = new JFrame("Video Test");
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel);
		frame.setSize( new Dimension(800, 600) );
		frame.setVisible(true);
		
		File video = new File("videos/test.avi");
		new PlayerTest(video, panel);
	}
}