Working with Movies
Get
some popcorn—Java can play
movies, with a little work. You’ll need to download and install
one of Java’s standard extension APIs, the
Java Media Framework (JMF).
The JMF defines a set of interfaces and classes in the
javax.media
and
javax.media.protocol packages. To use the JMF,
add jmf.jar to
your class path. Depending on what version of the JMF you download,
the installation program may do this for you.
We’ll only scratch the surface of JMF here, by working with an
important interface called
Player
. Specific implementations of
Player deal with different media types, like
Apple QuickTime
(.mov) and Windows Video
(.avi). Players are handed
out by a high-level class in the JMF called
Manager. One way to obtain a
Player is to specify the URL of a movie:
Player player = Manager.createPlayer(url);
Because video files are so large, and playing them
requires significant system resources, Players
have a multi-step lifecycle from the time they’re created to
the time they actually play something. We’ll just look at one
step, realizing. In this step, the
Player finds out (by looking at the media file)
what system resources it will need to actually play the media file.
player.realize( );
The realize( )
method returns right away; it kicks off the realizing process in a
separate thread. When the player is finished realizing, it sends out
an event. Once you receive this event, you can obtain a
Component that will show the media. The
Player has to be realized first so ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access