Native video codecs and Flash content with JMC
July 31st, 2008 | 16 Comments »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:
- 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.
- Add the lib/jmc.jar to the classpath of your project.
- Use one of the examples from the JavaOne presentation on JMC (see full code below).
- 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):
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.
Related posts:
- Extended support for native video codecs in JMC There’s nothing like the right link at the right time. Remy Rakic (Twitter alias lqd)...
- Native text rendering in Swing applications Yesterday i posted six screenshots divided in two groups and asked what is the difference....
- Native text rendering in Swing applications – how does it work? Two weeks ago i wrote about the first drop of Bramble plugin for Substance look-and-feel,...
- Native text rendering in Swing applications – ready, steady, go! The subject of native text rendering in Swing applications has been introduced on this blog...
Hi, I just tried out your sample code & was unable to get .mov files or .flv files to play properly. I could hear the sound in any of the files I tried. But the video stayed blank (a black square appeared in the upper left hand corner) for all of the files I tried. These files play fine using FFMPEG or using another player (VLC, QT). I’m am trying out JMC because FOBS4JMF doesn’t support 64-bit java 1.6 on OS X. Which is a different issue.
Do you know if there is some way to grab the actual frames from the video as it plays? I’m thinking about something similar to creating a processor in JMF where you can grab the pixels for processing or custom renderering, etc.
Also, the default JMediaPlayer looks horrible! (I understand it’s a preview version of course…)
Anyhow, just wondering if you’ve tried your code on OS X and what results you got.
Thanks, sj
Awesome work.
I was itching to get my hands dirty after reading “Filthy Rich Clients” but I lacked good playback of video clips in Java (JMF being pretty much left behind for dead)
Glad to see Sun picking up again with JMC
spiraljetty – the issues with blank videos should be addressed to the JavaFX team. Also, look at the code examples in the linked JavaOne presentation for additional functionality exposed by the JMediaPlayer and related classes.
Thanks
Kirill
So this is the death of JMF then. Well, I don’t think I can convince the powers-that-be to invest in JMC after we got burned so bad with the JMF. And I can’t blame them.
Is someone running a betting pools somewhere? I’d like to put $10 down on Sun abandoning or starting to neglect JMC within the next two years.
The only video file that works on my Windows XP system is a Silverlight video application demo in WMV format. Now -that- is funny. AVI and most WMV files just play audio. FLV and MOV just gives me “Unsupported media” exceptions.
And I can’t find any way of zooming the video to 1x/100%, 2x/200%, etc. setPreserveAspectRatio seems to be the only “advanced” API feature. Should I use getPreferredSize and pack instead :P
In two years when friendship bracelets powered by JavaFX is all the rage, you will eat those words :P
I think JMC survives until the CEO starts wearing a mohawk.
I think it’s obvious but might need mentioning. Native video codecs means you probably should install a nice and big codec pack before testing jmc :)
I got Windows Media Player, Quicktime, VLC, Vuze, FLV Player and even DivX. That’s one big ass codec pack.
JMediaPane.setSource() is not reusable. Just throws “null mediaPane” in my face. There is no media timeline listener, so you must guess where you are in order to keep JMediaPane.seek() in sync with the UI.
At first i had trouble with jmc too, i uninstalled my old but working codec pack, got the latest klite, and was then able to play some vids. Don’t know if you need quicktime alternative to play movs. VLC, FLV, quicktime, don’t install codecs as far as i know. Since jmc uses directshow, i tested vids in media player classic and windows media player, if they can’t read it, there’s little chance jmc will read them. Which is why it’s weird in your case, since i’m sure wmp reads your wmvs just fine. Ah the joys of native code …
Jan Erik,
Like lqd says, you need a good pack of codecs to go along with JMC at the moment. That would be divx, xvid, ffdshow, k-lite, haali, matroska and quite a few others. Google “codec packs” and always scan for viruses and trojans :)
Hello,
The javafx preview doesn’t have all v1.0 functionalities specially around video.
See : http://www.javafx.com/htdocs/whatscoming.html
and
I just success reading videos DV format and WMV.
It’s a good start …
Vincent
I was wrong about JMediaPane.setSource. It works, but there are so many problems that I just assumed the worst.
XVID – No video, good audio.
DIVX – No video, good audio.
WMV a/v 338kbps/291kbps – Video and audio.
WMV a/v 12240kbps/8000kbps – A few frames of video at random, broken audio.
My CPU is getting a little old, but still. All these movies play fine in several of my media players.
This codec pack solved most of my problems on XP. But I have no clue who is behind it.
http://www.cccp-project.net/
I’m as frustrated by JMF as anyone else, but I think JMC is good news. And I might observe, while Microsoft has stuck behind DirectShow, that may be neglect as much as anything else. Apple’s old QuickTime frameworks have been superseded with QTKit in the time that JMF has been around, and QT is about to get entirely overhauled for QT8. So, legitimate complaints with Sun aside, these things don’t last forever. The problem with JMF wasn’t that it didn’t last, it was that it didn’t really work very well in the *first place*. ;)
So, for that reason, I think JMC looks very promising.
I’m going to work with it in the hopes of making *sure* it gets noticed and supported.
The meta issue embedded in all this is that of software patents. This is what being able to patent formats results in. Adobe won’t “let” Sun write useful software.
When Sun first started, they got a visit from IBM’s lawyers. IBM’s lawyers presented a list of patents Sun had violated. They way I understand it, Sun’s lawyers looked them over and decided the allegations were junk. So IBM’s lawyers produced another list then another and another. The idea was, sure you can mount a defense against any individual crappy patent, but can you afford to mount a defense against all crappy patents?
In the end Sun caved, and paid the mob, er, I mean IBM, their “protection money”, that is, money for no service rendered but merely permission to contribute to the market and try to provide value.
To Sun’s credit, it truly does only patent things as a a kind of mutually assured destruction defense against the IBMs of this world.
Software patents and business method patents are junk economics that destroy value and that hand of death can reach out to any company, big or small at any time.
You’re kidding yourself if you think this doesn’t effect your company beause you’re too small / your market is too narrow / no one knows about you or there is no patent you’ve violated. None of the above it true.
The only way to stop this kind of destruction is to write your Congressperson or representative and tell
them that this is an issue with you.
You better believe that Microsoft and IBM have full time lobbyists whose offices are tiled in gold that are working full time to lobby against you. You need to make your voice heard, or the situation is going to get worse.
Well I have tried making my own player, but whatever format I use it seems to throw a MediaUnsupportedException =/. I have even used the sample code that was provided and it is still throwing the same exception. I do have a built in sound chip and the correct drivers so I am wondering why I keep having this problem ? =/