Java Reference
In-Depth Information
If you want to jump to a particular point in an audio clip, call
setMediaTime()
. You can find out
the current media time using
getMediaTime()
. The total time represented by the audio clip is
returned from
getDuration()
. For some types of streaming media, the duration cannot be
determined, in which case the special value
TIME_UNKNOWN
will be returned.
Players
can also loop, which means the audio clip is played over and over again. You can
control this behavior by calling
setLoopCount()
before the
Player
is started. Pass a value of
-1
to loop indefinitely.
Beyond the
Player
interface is a whole world of
Controls
. You can obtain a list of
Controls
for a
Player
by calling
getControls()
(a method
Player
inherits from the
Controllable
interface).
This method returns an array of
Controls
that are appropriate for the
Player
. The ABB only
defines a
VolumeControl
and a
ToneControl
, but implementations are free to provide other
controls appropriate for the content types and protocols they support.
To obtain just one control, pass its name to
Player
's
getControl()
method (again
inherited from
Controllable
). The name is the name of an interface in the
javax.microedition.media.control
package.
The
Player
must be in at least a
REALIZED
state to return its controls.
To use a
VolumeControl
to set playback volume to half its maximum, for example, you
would do something like this:
// Player player = Manager.createPlayer(...);
player.prefetch();
VolumeControl vc = (VolumeControl)player.getControl("VolumeControl");
vc.setLevel(50);
Listening for Player Events
Player
includes methods for adding and removing listeners that will be notified about various
milestones in the
Player
's life:
public void addPlayerListener(PlayerListener playerListener)
public void removePlayerListener(PlayerListener playerListener)
PlayerListener
defines a single method that is called with a variety of informational messages:
public void playerUpdate(Player player, String event, Object eventData)
The
player
parameter, of course, is the
Player
generating the event. The event is described
by a string,
event
, and may include additional information,
eventData
. Constants in the
PlayerListener
interface describe common events:
STARTED
,
END_OF_MEDIA
, and
VOLUME_CHANGED
are a few. See the API documentation for the full list.
Tones and Tone Sequences
You've already seen how easy it is to play single tones using
Manager
. There's a somewhat more
sophisticated tone sequence player lurking in the MIDP 2.0 media APIs. It's implemented
within the
Player
and
Control
architecture, which is kind of a kluge, considering that tone
sequences have little in common with sampled audio.
To obtain the tone sequence
Player
, just pass a special value (
Manager
's
TONE_DEVICE_LOCATOR
) to
createPlayer()
. If you examine
TONE_DEVICE_LOCATOR
, you'll see it is
Search WWH ::
Custom Search