Home | Русский

Finding multimedia content-type support of a mobile device

MMAPI gives facility of playing audio/video on mobile phones. MMAPI’s content-type/protocol support depends upon the mobile device capabilities.

The example below displays the mulitmedia file formats that are supported on a mobile phone:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;

public class Midlet extends MIDlet implements CommandListener {

private static final Command exit = new Command("Exit", Command.EXIT, 0);
private static final Command detail = new Command("Details", Command.ITEM, 1);
private static final Command audio = new Command("Audio", Command.ITEM, 2);
private static final Command vedio = new Command("Video", Command.ITEM, 3);
private static final Command polyphonic = new Command("Polyphonic sound", Command.ITEM, 4);
private Display display;
private List list;

public void startApp() {
if (display == null) {
display = Display.getDisplay(this);
list = new List(
"MultiMedia Device Capabilities", List.IMPLICIT,
Manager.getSupportedContentTypes(null), null);

list.setCommandListener(this);
list.addCommand(exit);
list.addCommand(detail);
list.addCommand(audio);
list.addCommand(vedio);
list.addCommand(polyphonic);

deviceCapabilities();

}
display.setCurrent(list);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable d) {
if (c == exit) {
destroyApp(true);
notifyDestroyed();
}
if (c == detail) {
showDetails();
}
if (c == audio) {
display.setCurrent(new Alert("audio", getCaptureSupport("audio"), null, AlertType.INFO));
}
if (c == vedio) {
display.setCurrent(new Alert("video", getCaptureSupport("video"), null, AlertType.INFO));
}
if (c == polyphonic) {
display.setCurrent(new Alert("Polyphony", getPolyphonySupport(), null, AlertType.INFO));
}
}

private void showDetails() {
int index = list.getSelectedIndex();
String type = list.getString(index);
String protocols[] = Manager.getSupportedProtocols(type);
Alert alert = new Alert(type, arrayToString(protocols), null, AlertType.INFO);
display.setCurrent(alert);
}

private String arrayToString(String[] items) {
if ((items == null) || (items.length == 0)) {
return "";
} else {
StringBuffer buffer = new StringBuffer(items[0]);
for (int i = 1; i < items.length; i++) {
buffer.append(", ");
buffer.append(items[i]);
}
return buffer.toString();
}
}

private void deviceCapabilities() {
String types[] = Manager.getSupportedContentTypes(null);
for (int i = 0; i < types.length; i++) {
String protocols[] =
Manager.getSupportedProtocols(types[i]);
}
}

private String getCaptureSupport(String media) {
StringBuffer sbuf = new StringBuffer(media);
String support = System.getProperty(
"supports." + media + ".capture");

if ((support != null) && (!support.trim().equals(""))) {
sbuf.append(" capture supported");
String supportRecording = System.getProperty(
"supports.recording");
if ((supportRecording != null) &&
(!supportRecording.trim().equals(""))) {
String recordingEncodings =
System.getProperty(media + ".encodings");
if ((recordingEncodings != null) &&
(!recordingEncodings.trim().equals(""))) {
sbuf.append(", recording supported to ");
sbuf.append(recordingEncodings);
} else {
sbuf.append(", recording not supported for this media format");
}
} else {
sbuf.append(", recording not supported");
}

String snapshotEncodings = System.getProperty(
media + ".snapshot.encodings");

if (snapshotEncodings != null) {
sbuf.append(", snapshots supported to ");
sbuf.append(snapshotEncodings);
}
} else {
sbuf.append(" capture not supported");
}
return sbuf.toString();
}

private String getPolyphonySupport() {
String mixing = System.getProperty("supports.mixing");
if (mixing != null) {
return "Polyphonic sound supported";
} else {
return "Polyphonic sound not supported";
}
}
}
This entry was written by admin , posted on Monday November 24 2008at 05:11 am , filed under J2ME and tagged , , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

Leave a Reply

You must be logged in to post a comment.