Java Reference
In-Depth Information
private void showException(Exception e) {
Alert a = new Alert("Exception", e.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mMainScreen);
}
}
To play the audio file over the Internet, you will need to set up the MIDlet property
AudioMIDlet-URL to have the following value:
http://65.215.221.148:8080/wj2/res/relax.wav
Playing MP3 Music
If your device supports the playback of MP3 music through MMAPI, the AudioMIDlet presented
previously can be used to play MP3 music that is retrieved using HTTP by simply changing the
AudioMIDlet-URL property to refer to an MP3 file. For example:
http://65.215.221.148:8080/wj2/res/mytrack.mp3
When you want to play an MP3 soundtrack from a resource file, you will need to change
the following line in the playFromResource() method:
InputStream in = getClass().getResourceAsStream("/mytrack.mp3");
Player player = Manager.createPlayer(in, "audio/mpeg");
While the HTTP protocol enables the server to set the content , you must set the type explictly
when playing back from a resource file. The content type string for MP3 is “audio/mpeg”. (See
http://www.iana.org/assignments/media-types/ for more types.) The next section explores
content type further.
Note Playback of MP3 files is not a mandatory requirement of MIDP or JTWI 1.0. In general, device manu-
facturers must pay additional licensing fees to implement MP3 playback. If your application or game needs to
be usable across a variety of devices, it is wise not to have dependency on MP3 playback.
MMAPI Media Concepts
Audio data comes in a variety of content types . A content type is really just a file format, a spec-
ification that tells how each bit in the data contributes to the resulting sound. Common audio
content types are MP3, AIFF, and WAV. In the MIDP 2.0 ABB, content types are specified using
MIME types, which use a string to specify a primary and secondary type. For example, the MIME
type for WAV audio is “audio/x-wav”.
The content type tells how to translate bits into sound, but that's only half the battle. A protocol
specifies how to get the data from its original location to the place where it will be rendered.
You could use HTTP, for example, to transfer audio data from a server to a MIDP device.
 
Search WWH ::




Custom Search