Java Reference
In-Depth Information
try {
Player player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
player.realize();
ToneControl tc = (ToneControl)player.getControl("ToneControl");
tc.setSequence(sequence);
player.start();
}
catch (Exception e) {
Alert a = new Alert("Exception", e.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mMainScreen);
}
}
}
Remember, Player 's start() method does not block. If you want, you can start all three
songs running simultaneously in the emulator. This works because the toolkit emulator is
using a polyphonic device to play the tone sequences. On a real device, playing multiple sequences
simultaneously is probably not possible. But you can set one sequence running, and assuming
it doesn't suck up too much processor time, your MIDlet can go and do other tasks, like drawing
a game display or connecting to a network.
The Mobile Media API
MIDP audio support is only a subset of the full power of the Mobile Media API. If you're using
the J2ME Wireless Toolkit, its emulators support the full MMAPI by default. This means that you
have other APIs available and several additional content types supported by the implementation.
If you'd like to remove MMAPI support, leaving only MIDP audio, click the Settings button
from KToolbar; this will display the API Selection tab. You can uncheck the Mobile Media API
(JSR 135) if you do not wish to use it.
Playing Video Using the MMAPI
You already know most of the concepts needed to play video on your phone. The great thing
about the design of the MMAPI is that you can use the exact same approach to play video, as
you have with audio.
You need to create a player, realize it, and then call start() on it to play video. These are
the same steps as in the playback of audio. Only the content type and file extension change.
The VideoMIDlet code in Listing 16-5 is a modified version of the AudioMIDlet presented
earlier. In this case, VideoMIDlet plays a MPEG1 video file, called fish.mpg , from the resource.
Look back at AudioMIDlet , compare the player creation code in the playFromResource()
method of Listing 16-5:
InputStream in = getClass().getResourceAsStream("/fish.mpg");
mPlayer = Manager.createPlayer(in, "video/mpeg");
The only change is the content type, now “video/mpeg”; and the file name, now “/fish.mpg”.
Search WWH ::




Custom Search