Native video codecs and Flash content with JMC

July 31st, 2008

My number one wish for Java desktop for this year was cross-platform support for H.264 and FLV formats. Today has marked a first (and hopefully not last) step towards playing video content in Swing application – Java Media Components which is a part of JavaFX preview SDK.

Here is what you need to do to use JMC in your Swing application:

  1. Download and install the JavaFX preview SDK. The rest of the steps assumes that the SDK has been installed in the C:|Program Files/JavaFX/javafx-sdk1.0pre1 folder.
  2. Add the lib/jmc.jar to the classpath of your project.
  3. Use one of the examples from the JavaOne presentation on JMC (see full code below).
  4. Run the application with the following VM flag: -Djava.library.path=”C:/Program Files/JavaFX/javafx-sdk1.0pre1/lib”

I have tested the current JMC drop on the following formats:

  • Flash content – FLV and SWF files. While the regular content plays correctly, i have not been able to interact with the content of an interactive SWF file.
  • Container formats – AVI, MPG, MKV.

I have not been able to play the MOV files (H.264). Hopefully this will be addressed in the future releases of JMC, even before providing a cross-platform codec from On2.

Here is a sample screenshot of JMC playing an MKV file on a frame with translucent reflection (click to see the full size version):

JMC playing an MKV file in a frame with translucent reflection
JMC playing an MKV file in a frame with translucent reflection

MKV is a popular container format for video / audio content, and it is used by Azureus Vuze application. The screenshot above shows the trailer of “Watchmen” movie, and while Azureus uses the native executable for MPlayer to play these files, JMC goes a step further and exposes a Java API layer to Swing applications. You can find the full source code behind the screenshot at this location.