Java Reference
In-Depth Information
If the type of control you want is not available, a
NULL
value is
returned (which you should always check for). You will also need to cast
the control appropriately before using it:
VolumeControl volC = (VolumeControl) player.getControl("VolumeControl");
if (volC != null)
volC.setVolume(50);
The availability of support for controls depends on a number of fac-
tors, such as the media type and the phone model. Only
ToneControl
and
VolumeControl
are available as part of the MIDP audio subset.
The remainder are specific to MMAPI. You can check which controls
are supported by a certain
Player
by calling its
getControls()
method, which returns an array containing all available controls. You
can then use
instanceof
to ascertain whether the control you want is
available:
Control[] controls = player.getControls();
for (int i = 0; i < controls.length; i++)
{
if (controls[i] instanceof VolumeControl)
{
VolumeControl volC = (VolumeControl) controls[i]
volC.setVolume(50);
}
if (controls[i] instanceof VideoControl)
{
VideoControl vidC = (VideoControl) controls[i]
vidC.setDisplayFullScreen(true);
}
}
// allow controls to be garbage collected
controls = null;
Note that
getControl()
and
getControls()
cannot be invoked
on a
Player
in the UNREALIZED or CLOSED states; doing so will cause
an
IllegalStateException
to be thrown.
Aside from using a
Player
, there is a further option to play simple
tones or tone sequences directly using the static
Manager.playTone()
method. However, you normally want the additional flexibility provided
by working with a
Player
(configured for tones) and a
ToneControl
(see Section 2.9.8).
The
PlayerListener
interface provides a
playerUpdate()
me-
thod for receiving asynchronous events from a
Player
. Any user-defined
class may implement this interface and then register the
PlayerLis-
tener
using the
addPlayerListener()
method. The
PlayerLis-
tener
listens for a range of standard pre-defined events including
STARTED, STOPPED and END OF MEDIA. For a list of all the standard
events refer to the MMAPI specification.