I am building a small Swing application that I would like to embed a movie within. Importantly, this application is a WebStart application - and the library should be able to be packaged within the jnlp that I launch -i.e, not dependent on native libraries.
I am aware of and have tried JMF but the format compatibility I believe to be relatively poor when compared to other frameworks out there.
Could someone please provide a sample code snippet of a simple implementation using their recommended library?
Many thanks in advance.
Some considerations for JavaFX as a solution as a Java based media playback framework.
- As of Jdk7u4, JavaFX is co-bundled with the jdk for Mac and Windows
(XP, Vista, 7, 32 and 64 bit).
- JavaFX can be embedded in a Swing App.
- JavaFX includes native libraries, but any Java Framework is going to need native libraries to do video well.
- A comprehensive deployment toolkit is included with the JavaFX SDK and/or includes the ability to generate jnlp based deployments.
- JavaFX 2.1 supports vp6 encoded flvs (older format) as well as some more modern and oft-used encoding formats such as mp4/aac/mp3.
- JavaFX only supports limited media codecs and container formats, e.g. if you have a codec installed on your machine and can play a file encoded in that format in, for example chrome, windows media player, or flash that does not guarantee that the same file will play in JavaFX.
- Playback of mp4 on XP or Linux requires a user to manually install the necessary codec, but other platforms (osx, win7, vista) do not require manual mp4 codec install.
- Use of JavaFX on a mac requires the user to use OpenJDK 7 for Mac, not the Apple JDK.
- JavaFX support for jnlp launched apps on Macs won't be available until later this year (2012) and similarly for Linux.
- You could probably bundle the entire JavaFX platform with your app in a jnlp (though I haven't seen anybody do that yet).
- The recommended method for a jnlp deployment would be to add a specification of a minimum JavaFX environment to the jnlp and have the JavaFX deployment toolkit and webstart take care of ensuring that it was present and installed correctly on the user's machine.
- Interaction between Swing and JavaFX requires some inconvenience and care around threading and also a slightly different app launching code between Swing and JavaFX. Some people have complained about this on forums, most don't seem to have had too many issues.
- For better or for worse (I believe better), JavaFX is likely the only media and client development framework from Oracle which is receiving ongoing major development and new features.
- Eventually (this year or next) JavaFX will included in all new Java runtimes for all major consumer platforms which run modern versions of Java SE.
- Community support for development in JavaFX from Oracle and 3rd parties is (I believe) good.
Here is a sample JavaFX app which plays a video:
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;
public class VideoPlayerExample extends Application {
public static void main(String[] args) throws Exception { launch(args); }
@Override public void start(final Stage stage) throws Exception {
final MediaPlayer oracleVid = new MediaPlayer(
new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv")
);
stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208));
stage.show();
oracleVid.play();
}
}
Although I have not had any problems with formats compatibility o JMF you can take a look in JavaFX that was designed to be a competitor to Flash, so should support all media formats and codecs.
You can also embed Flash player into java application using JNI/JNA but it seems too complicated. I'd recommend you to start with JMF and look for other solution only if you really have problems.