Java by API/javax.microedition.media/Manager — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:38, 31 мая 2010
Содержание
- 1 Manager: createPlayer(InputStream arg0, String arg1) throws IOException, MediaException
- 2 Manager: getSupportedContentTypes(String protocol)
- 3 Manager: getSupportedProtocols(String content_type)
- 4 Manager.MIDI_DEVICE_LOCATOR
- 5 Manager: playTone(int note, int duration, int volume) throws MediaException
- 6 Manager.TONE_DEVICE_LOCATOR
Manager: createPlayer(InputStream arg0, String arg1) throws IOException, MediaException
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.midlet.MIDlet;
public class DistributedToneMIDlet extends MIDlet {
private Player tonePlayer;
public DistributedToneMIDlet() {
try {
tonePlayer = Manager.createPlayer(getClass().getResourceAsStream(
"/x.jts"), "audio/x-tone-seq");
} catch(Exception e) {
System.err.println(e);
}
}
public void startApp() {
try {
if(tonePlayer != null)
tonePlayer.start();
} catch(Exception e) {
System.err.println(e);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Manager: getSupportedContentTypes(String protocol)
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.midlet.MIDlet;
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]);
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();
}
}
Manager: getSupportedProtocols(String content_type)
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.midlet.MIDlet;
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]);
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();
}
}
Manager.MIDI_DEVICE_LOCATOR
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;
public class MIDICapabilitiesMIDlet extends MIDlet {
public void startApp() {
try {
Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
p.prefetch();
MIDIControl mControl = (MIDIControl) p
.getControl("javax.microedition.media.control.MIDIControl");
String msg = mControl.isBankQuerySupported() ? "MIDIControl is fully supported"
: "Minimum MIDIControl is provided";
Display.getDisplay(this).setCurrent(new Alert("Message", msg, null, AlertType.INFO));
} catch (Exception e) {
System.err.println(e);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Manager: playTone(int note, int duration, int volume) throws MediaException
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
public class CSharpMIDlet extends MIDlet {
public CSharpMIDlet() {
}
public void startApp() {
try {
Manager.playTone(61, 5000, 100);
} catch(MediaException me) { System.err.println(me); }
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Manager.TONE_DEVICE_LOCATOR
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.ToneControl;
import javax.microedition.midlet.MIDlet;
public class ToneMIDlet extends MIDlet implements CommandListener {
private Display mDisplay;
private List mMainScreen;
public void startApp() {
mDisplay = Display.getDisplay(this);
if (mMainScreen == null) {
mMainScreen = new List("AudioMIDlet", List.IMPLICIT);
mMainScreen.addCommand(new Command("Exit", Command.EXIT, 0));
mMainScreen.addCommand(new Command("Play", Command.SCREEN, 0));
mMainScreen.setCommandListener(this);
}
mDisplay.setCurrent(mMainScreen);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
else
run();
}
public void run() {
byte[] sequence = null;
sequence = new byte[] { ToneControl.VERSION, 1, ToneControl.TEMPO, 22,
ToneControl.BLOCK_START, 0, 60, 8, 62, 4, 64,
ToneControl.SET_VOLUME, 50, ToneControl.PLAY_BLOCK, 1, ToneControl.SET_VOLUME, 100,
ToneControl.PLAY_BLOCK, 0, };
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);
}
}
}