MIDlet详细代码:
package test;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import java.io.*;
public class SoundMIDlet extends MIDlet
{
private Player player = null;
/** Constructor */
public SoundMIDlet() {
try {
InputStream is = this.getClass().getResourceAsStream(
"/audio/bark.wav");
player = Manager.createPlayer(is, "audio/x-wav");
}
catch (IOException e) {
System.out.println("1:" + e);
}
catch (MediaException e) {
System.out.println("2:" + e);
}
catch (Exception e) {
System.out.println("3:" + e);
}
}
/** Main method */
public void startApp() {
if (player != null) {
try {
player.start();
}
catch (MediaException e) {
System.out.println("4:" + e);
}
}
}
/** Handle pausing the MIDlet */
public void pauseApp() {
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
}
}
其中要注意的是:音频文件bark.wav放在res包中audio子包内,无需再写res,路径名为:/audio/bark.wav