Any simple (and up to date) Java frameworks for embedding movies within a Swing Application?

Some considerations for JavaFX as a solution as a Java based media playback framework.

  1. As of Jdk7u4, JavaFX is co-bundled with the jdk for Mac and Windows
    (XP, Vista, 7, 32 and 64 bit).
  2. JavaFX can be embedded in a Swing App.
  3. JavaFX includes native libraries, but any Java Framework is going to need native libraries to do video well.
  4. A comprehensive deployment toolkit is included with the JavaFX SDK and/or includes the ability to generate jnlp based deployments.
  5. 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.
  6. 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.
  7. 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.
  8. Use of JavaFX on a mac requires the user to use OpenJDK 7 for Mac, not the Apple JDK.
  9. JavaFX support for jnlp launched apps on Macs won’t be available until later this year (2012) and similarly for Linux.
  10. You could probably bundle the entire JavaFX platform with your app in a jnlp (though I haven’t seen anybody do that yet).
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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();
  }
}

Leave a Comment