August 20, 2009

Video in Java, no more JMF please, use JavaFX!

I often get email from people asking me to help them with playing video in Java using JMF & FOBS, probably because of my post from last year: playing-flash-video-flv-with-java

The reason why I'm writing this is to make it clear to people that time has moved on since last year, and the long awaited Java Media Components framework which was annouced a few years ago has finally hit the shelves as the media playing capability built into JavaFX. So rest assured, you don't have to hack your way around JMF to integrate FFMPEG to play all your movies.

Just follow this link to the JavaFX samples website, there are plenty of better ways to play video in Java than a year ago. But you'd have to use JavaFX for that, don't worry JavaFX is simple and runs under Java so it integrates well with a regular Java app/applet.

7 comments:

  1. Hey man, i couldn't find a good tutorial describing how to embed javafx in a swing component... Could you please provide one? All i found was official hacks(!!!), use of libraries coming from nowhere and things like that. Thnx.
    (I am mainly interested into using mediaBox example in my app)

    ReplyDelete
    Replies
    1. Go to http://docs.oracle.com/javafx/2/swing/overview.htm

      Delete
  2. The JFXtras project has such a component: http://karussell.wordpress.com/2009/06/15/embed-javafx-1-2-into-swing-with-jfxtras/

    But since the JavaFX 2.0 announcement at JavaOne apparently a java api for media will be available during the first half of 2011. For more information check out the JavaFX 2.0 roadmap: http://javafx.com/roadmap/#media

    ReplyDelete
  3. many thanx, for the answer my friend. I have already found this but i couldn't believe that a very promising technology does not have the background to "conquer the world" (if flex and silverlight let it happen). I am going to follow your older tutorial using old pure Java, and the library you suggested. Playing a little with mediaBox sample from NetBeans causes very funny results.(Unexpected behavor with "file:///" protocol, fails to run when trying to play the example provide flv from harddisk...). Thanks again for the answer (maybe i should have used Qt/C++)

    ReplyDelete
  4. I had a similar problem with a local FLV (file://) and found the following solution:

    var file = new File("C:/PROJECT/videos/on2tm_352.flv");

    Media {
    source: "{file.toURI()}"
    }

    (from: http://stackoverflow.com/questions/2996425/how-to-access-local-media-file-on-my-computer-in-javafx)

    Just it case it helps anyone!

    ReplyDelete