One of the least understood aspects of the ABB is its supported content types. MIDP 2.0 is very flexible about the content types and protocols an implementation may support. All the specification says is that if sampled audio is supported at all, then 8-bit PCM WAV must be supported. Beyond that, the sky's the limit.
If you do ask Manager for data or a protocol that it can't handle, a MediaException will be thrown.
You can find out, at runtime, what content types and protocols are supported using two methods in the Manager class:
public static String getSupportedContentTypes(String protocol) public static String getSupportedProtocols(String content_type)
You can find out the content types for a given protocol, or the protocols for a given content. If you supply null to either of these methods, you'll get a complete list of supported content types or protocols.
The MIDlet in Listing 12-3 finds all supported content types and prints out the corresponding protocols for each.
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
public class MediaInformationMIDlet
extends MIDlet
implements CommandListener {
private Form mInformationForm;
public void startApp() {
if (mInformationForm == null) {
mInformationForm =
new Form("Content types and protocols");
String[] contentTypes =
Manager.getSupportedContentTypes(null);
for (int i = 0; i < contentTypes.length; i++) {
String[] protocols =
Manager.getSupportedProtocols(contentTypes[i]);
for (int j = 0; j < protocols.length; j++) {
StringItem si = new StringItem(contentTypes[i] + ": ",
protocols[j]);
si.setLayout(Item.LAYOUT_NEWLINE_AFTER);
mInformationForm.append(si);
}
}
Command exitCommand = new Command("Exit", Command.EXIT, 0);
mInformationForm.addCommand(exitCommand);
mInformationForm.setCommandListener(this);
}
Display.getDisplay(this).setCurrent(mInformationForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}
}
Figure 12-4 shows the results if you run MediaInformationMIDlet on the J2ME Wireless Toolkit emulator (in the 2.0 beta 2 release). There are three things to understand about this list:
HTTP is a file transfer protocol, not a streaming media protocol. If you specify a media file with HTTP, the whole file will be downloaded before playback begins. By contrast, some devices may support real streaming protocols like RTP (see http://www.ietf.org/rfc/rfc1889.txt).
The "audio/x-tone-seq" content type is not really sampled audio; it's a special case for tone sequences, which I'll describe soon.
The list includes some features and content types (video, MIDI, audio capture) from the wireless toolkit's MMAPI implementation. If you want to see a bare-bones list of supported content types and protocols, turn off the MMAPI support as described near the end of this chapter.
To find out the content type of an existing Player, just call getContentType().