Java Reference
In-Depth Information
iif (( visualComponent = thePlayer . getVisualComponent ()) != null
null )
cp . add ( BorderLayout . CENTER , visualComponent );
iif (( controlComponent =
thePlayer . getControlPanelComponent ()) != null
null )
cp . add ( BorderLayout . SOUTH , controlComponent );
// resize the main window
iif ( parentFrame != null
null ) {
parentFrame . pack ();
parentFrame . setTitle ( mediaName );
}
}
}
public
public static
void main ( String [] argv ) {
JFrame f = new
static void
new JFrame ( "JMF Player Demo" );
Container frameCP = f . getContentPane ();
final
final String musicURL = argv . length == 0 ?
"file:/home/ian/Music/Classical/Rachmaninoff Prelude C_ min.mp3" :
argv [ 0 ];
JMFPlayer p = new
new JMFPlayer ( f , musicURL );
frameCP . add ( BorderLayout . CENTER , p );
f . setSize ( 200 , 200 );
f . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
f . setVisible ( true
true );
}
}
The optional Java Media Framework includes much more functionality than this example
shows. However, the ability to display a QuickTime or MPEG movie with only a few lines of
code is one of JMF's most endearing young charms. We load the media file from a URL and
create a Player object to manage it. If it makes sense for the given player to have a control-
ler, it will have one, and we add it to the bottom of the screen. Controllers may include
volume controls, forward/backward buttons, position sliders, etc. However, we don't have to
care: we get a component that contains all the appropriate controls for the kind of media clip
for which we've created the player. If the given player represents a medium with a visual
component (like a movie or a bitmap image), we add this to the center of the screen.
Of course, there is much more to the JMF API than this. You can, for example, coordinate
playing of audio and video with each other or with other events.
Search WWH ::




Custom Search