The Java Media Components API promises to finally deliver an easy to use and easy to install platform for media playback in the Java Virtual Machine, and so far, they seem to have succeeded!
The other API that offers media playback on the JVM is the Java Media Framework: a library that requires the user to configure a registry containing information on available playback (and capture) devices and forces the developer to craft many lines of code just to play some video. Especially the configuration part for the user’s system makes the library in my opinion useless for inclusion in consumer applications.
The Java Media Components API is much easier and obtaining the library is the hardest part at this moment. There seems to be no public project, and the only access seems to be to follow these steps:
If you fail to include the last step, the system will complain about not being able to find a codec for all media you’re trying to play. Currently this dependency on an external library means that the media components library is only usable on Windows and Mac. Hopefully the library will have evolved and ported when the final JavaFX release arrives.
The library is built around several usage patterns, that either offer an easier interface or give the developer more control. Let’s have a look.
The first option is the JMediaPlayer. This is a Swing component providing a the UI for both the video playback, as well as the controls for the user. THe following illustrates the use. Note that the actual component requires just one statement!
The second pattern gives you more freedom, and doesn’t provide any visible controls: you’ll have to implement the interactions yourself. Since this would again require basically one line plus some code for a call to play, I spiced the application with a little bit of the SceneGraph API, inspired by this post of Kirill Grouchnikov.
The final way to use the library is doing without a Swing component. The MediaProvider class provides access to several so-called controls. These give you access to information on and control over audio, subtitles, tracks, video and rendering. This allows one to apply an effect to the video-frames before they are rendered or to render them into a 3D scene. The best way to learn about the controls is by looking at the methods provided by the different classes from within you favourite IDE.
Although currently the native codecs are the only ones available, thus limiting you in choice and complicating the delivery of media to all platforms, Sun is working on providing a cross-platform codec with JMC, which will be licensed from On2. Hopefully this will be ready when JavaFX is released in a few weeks. The JavaOne talk also mentioned that people are working on adding video capture to the API, allowing for video-conferencing. If they succeed we finally have a really nice API to work with media on the JVM!
JavaOne session TS-6509 - the session on JMC at JavaOne 2008
No Pingbacks for this post yet...
This post has 3 feedbacks awaiting moderation...
Personal blog on my interests.
|<< <||> >>|