Java Reference
In-Depth Information
In this approach, the web server provides the content type of the data. Another approach
is to obtain an InputStream to the audio data, and then create a Player by telling Manager the
content type of the data. This is handy for reading audio files that are stored as resources in the
MIDlet suite JAR. For example:
InputStream in = getClass().getResourceAsStream("/relax.wav");
Player player = Manager.createPlayer(in, "audio/x-wav");
player.start();
Listing 16-2 is a simple MIDlet that demonstrates both techniques.
Listing 16-2. Playing Audio Files
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
public class AudioMIDlet
extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private List mMainScreen;
public void startApp() {
mDisplay = Display.getDisplay(this);
if (mMainScreen == null) {
mMainScreen = new List("AudioMIDlet", List.IMPLICIT);
mMainScreen.append("Via HTTP", null);
mMainScreen.append("From resource", null);
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) {}
Search WWH ::




Custom Search