
54
BlackBerry Java Development Environment Development Guide
Play media
Listen for media player events
Task Steps
Prepare the media player. 1. Invoke Player.realize().
2. Invoke Player.prefetch().
Start the media player. >Invoke Player.start(). The Player returns to the Prefetched state when you invoke
Player.stop() or when it reaches the end of the media file.
try {
Player p = Manager.createPlayer("http://www.test.rim.net/abc.wav");
p.start();
} catch (MediaException pe) {
} catch (IOException ioe) {
}
Determine the controls that a
media player supports.
1. Invoke Player.getControls().
2. To provide additional functionality for a media player, use one or more of the controls that the media
player supports.
You can use the same object to access multiple controls: for example, one object can be both a
VolumeControl and a ToneControl. The
javax.microedition.media package contains a number of
Control interfaces. See the
API Reference in the BlackBerry® Java Development Environment for more
information about the
javax.microedition.media package.
Adjust the volume of the
media player.
1. Invoke VolumeControl().
2. Define a volume value in the following range:
• 0: no volume
• 100: maximum volume level
The PlayerListener sends a VOLUME_CHANGED event when its state changes.
Close the media player. >Invoke Player.stop().
Task Steps
Listen for changes to the
media player state.
1. Implement PlayerListener.
2. To register the player listener, invoke addPlayerListener.
private void doPlay()
throws IOException, MediaException
{Player p = Manager.createPlayer("http://www.rim.com/rim.mp3");
p.addPlayerListener(this);
p.realize();
p.prefetch();
p.start();
}
Komentáře k této Příručce