TOC Prev Next
You create a Player indirectly through the media Manager. To display the
Player, you get the Player's components and add them to the applet's
presentation space or application window.
3.1 Creating a Player
When you need a new Player, you request it from the Manager by calling
createPlayer. The Manager uses the media URL or MediaLocator that you
specify to create an appropriate Player.
A URL can only be successfully constructed if the appropriate corresponding URLStreamHandler
is installed. MediaLocator doesn't have this restriction.
This level of indirection allows new Players to be integrated seamlessly. From
the client perspective, a new Player is always created the same way, even though
the Player might actually be constructed from interchangeable parts or dynamically
loaded at runtime.
3.2 Displaying a Player and Player Controls
JMF specifies the timing and rendering model for displaying a media stream, but
a Player's interface components are actually displayed using java.awt, Java's
core package for screen display. A Player can have two types of AWT components,
its visual component and its control components.
3.2.1 Displaying a Player's Visual Component
The component in which a Player displays its media data is called its visual component.
Even an audio Player might have a visual component, such as a waveform
display or animated character.
To display a Player's visual component, you:
- Get the component by calling
getVisualComponent.
- Add it to the applet's presentation space or application window.
You can access the Player's display properties, such as its x and y coordinates,
through its visual component. The layout of the Player components is controlled
through the AWT layout manager.
3.2.2 Displaying a Player's Controls
A Player often has a control panel that allows the user to control the media presentation.
For example, a Player might be associated with a set of buttons to
start, stop, and pause the media stream, and with a slider control to adjust the volume.
Every Java Media Player provides a default control panel. To display a Player's
default control panel, you get it by calling getControlPanelComponent and add
it to the applet's presentation space or application window. If you prefer to define
a custom user-interface, you have access to the interfaces through which the standard
control panel is implemented.
A Player's control-panel component often interacts with both the Player and
the Player's controls. For example, to start and stop the Player or set its media
time, the control panel calls the Player directly. But many Players have other
properties that can be managed by the user. For example, a video Player might
allow the user to adjust brightness and contrast, which are not managed through
the Player interface.To handle these types of controls, JMF defines the Control
interface.
A media Player can have any number of Control objects that define control
behaviors and have corresponding user interface components. You can get these
controls by calling getControls on the Player. For example, to determine if a
Player supports the CachingControl interface and get the CachingControl if it
does, you can call getControls:
Control[] controls = player.getControls();
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof CachingControl) {
cachingControl = (CachingControl) controls[i];
}
}
|
What controls are supported by a particular Player depends on the Player implementation.
3.2.3 Displaying a Gain Control Component
GainControl extends the Control interface to provide a standard API for adjusting
audio gain. To get this control, you must call getGainControl; getControls
does not return a Player's GainControl. GainControl provides methods for
adjusting the audio volume, such as setLevel and setMute. Like other controls,
the GainControl is associated with a GUI component that can be added to an
applet's presentation space or an application window.
3.2.4 Displaying a Player's Download Progress
Downloading media data can be a time consuming process. In cases where the
user must wait while data is downloaded, a progress bar is often displayed to reassure
the user that the download is proceeding and to give some indication of how
long the process will take. The CachingControl interface is a special type of
Control supported by Players that can report their download progress. You can
use this interface to display a download progress bar to the user.
You can call getControls to determine whether or not a Player supports the
CachingControl interface. If it does, the Player will post a CachingControlEvent
whenever the progress bar needs to be updated. If you implement your own
progress bar component, you can listen for this event and update the download
progress whenever CachingControlEvent is posted.
A CachingControl also provides a default progress bar component that is automatically
updated as the download progresses. To use the default progress bar in
an applet:
- Implement the
ControllerListener interface and listen for
CachingControlEvents in controllerUpdate.
- The first time you receive a
CachingControlEvent:
a. Call getCachingControl on the event to get the caching control.
b. Call getProgressBar on the CachingControl to get the default progress
bar component.
c. Add the progress bar component to the applet's presentation space.
- Each time you receive a
CachingControlEvent, check to see if the download
is complete. When getContentProgress returns the same value as
getContentLength, remove the progress bar.
TOC Prev Next
|