Skip to content

MattHicks.com

Programming on the Edge

Menu
Menu

Java Media Components (JMC) in Swing

Posted on May 4, 2009 by mhicks

If you’re like me and have been really excited by all the hype of JMC, but think of yourself as a Java developer and not a fly being beckoned to the newest scripting framework with its bright and illuminating glow (JavaFX that is) then JMC comes as something of a disappointment. After all, every article on the web referencing JMC seems to inseparably link JavaFX and JMC as if they absolutely *MUST* go together.

However, this is not the case. I’ve blogged before about the evils of JavaFX and how Java developers can leverage the functionality without selling your soul to the scripting demons:

http://www.matthicks.com/2009/02/i-hate-javafx-i-love-javafx.html

Someone else has taken this another step by taking the same approach for JMC:

http://nishimotz.com/2009/03/10/using-jmc-from-java/

Now, though what Takuya wrote is fully functional, I hate the idea of having to include JavaFX just to use JMC. After a bit of digging I have come to find what seems to be a hidden feature (maybe Sun just thinks the idea of someone using it outside of JavaFX is ridiculous and not worth mentioning?), the jmc.jar file you get with JavaFX has some interesting classes in it that you can take advantage of in your own Swing applications without any hackery at all:


package test;

import java.io.File;

import javax.swing.JFrame;

import com.sun.media.jmc.JMediaPlayer;

public class TestJMC {
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame("Testing JMC"); {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);

JMediaPlayer player = new JMediaPlayer(new File("trailer_1080p.mov").toURI()); {
frame.add(player);
}

frame.setVisible(true);
}
}
}

I hate it when people give references like this and don’t give any mention of a test file that can be used along with it, so to let you know what I used, I simply grabbed the trailer for “Big Buck Bunny” here:

http://www.bigbuckbunny.org/index.php/trailer-page/

What’s awesome is that any one of them should work fine. Now, the player controls kind of suck, but in that same package there are other, probably more useful Swing classes: JMediaPane and JMediaView.

One last note. You need to include the jmc.dll (or the correct native lib for your OS) file in your library path to be able to play or you’ll get unfriendly errors.

Have fun being able to leverage full video playing in your Swing applications.

3 thoughts on “Java Media Components (JMC) in Swing”

  1. Angus Forbes says:
    May 4, 2009 at 3:41 pm

    Hi, I made a simple wrapper for JMC called “jmcvideo”. You can find the source and jar on the following page: http://www.mat.ucsb.edu/~a.forbes/PROCESSING/jmcvideo/jmcvideo.html

    It was made for Processing, but you should be able to adapt it for any Java project without too much trouble.

    -Angus

    Reply
  2. Matt Hicks says:
    May 4, 2009 at 3:54 pm

    I saw this when I was searching online and disregarded it since it looked specific to JOGL. I did bookmark it for later investigation though. 😉

    Reply
  3. Unknown says:
    May 19, 2009 at 6:40 am

    The problem with all these JMC/Swing integration projects is that the Sun JavaFX license SPECIFICALLY PROHIBITS redistributing all or any JavaFX components. That definitely includes JMC. So, while you can run hobby projects all you want with jmc.jar and jmc.dll, the moment you try doing something commercial, you’re on the wrong side of the law.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Courio: E-Mail 2.0
  • Scribe 2.0: Fastest JVM Logger in the World!
  • Logging Performance
  • Publicity in Open-Source
  • Play Framework for Scala: An Evaluation

Recent Comments

  1. Luke Hutchison on Multithreaded Unzip?
  2. Luke Hutchison on Multithreaded Unzip?
  3. Unknown on Multithreaded Unzip?
  4. D L on Multithreaded Unzip?
  5. Matt Hicks on Multithreaded Unzip?

Archives

  • March 2019
  • February 2018
  • January 2017
  • June 2016
  • July 2015
  • February 2015
  • December 2014
  • September 2013
  • March 2013
  • February 2013
  • January 2013
  • November 2011
  • December 2010
  • October 2010
  • July 2010
  • June 2010
  • May 2010
  • October 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • March 2009
  • February 2009
  • September 2008
  • July 2008
  • May 2008
  • March 2008
  • January 2008
  • December 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007

Categories

  • adobe
  • android
  • apple
  • beans
  • benchmark
  • challenge
  • chat
  • comparison
  • courio
  • eclipse
  • example
  • flex
  • framework
  • games
  • hacks
  • helios
  • html
  • hyperscala
  • ios
  • java
  • javafx
  • javascript
  • jcommon
  • jgn
  • jmc
  • jseamless
  • jug
  • kickstarter
  • learning
  • linux
  • log4j
  • logging
  • mac
  • media
  • mediacenter
  • methodology
  • mobile
  • mythtv
  • nabo
  • open-source
  • opengl
  • opinion
  • personal
  • playframework
  • pojo
  • programming
  • publicity
  • rant
  • raspberrypi
  • review
  • scala
  • scribe
  • script
  • sgine
  • social
  • sudoku
  • sun
  • swing
  • tutorial
  • Uncategorized
  • webframework
  • website
  • windows
  • xjava
© 2025 MattHicks.com | Powered by Minimalist Blog WordPress Theme