j2me + javax.microedition.midlet.MediaException:听起来不允许

时间:2011-11-05 02:49:31

标签: java-me midp midlet mmapi series-40

我正在尝试播放MP3并出现意外错误 我在3天之前测试了我的应用

在我的设备上运行得很好

但现在即使是同一个jar文件也会给我以下错误。

javax.microedition.midlet.MediaException:Sounds not allowed

执行此行时出现错误     player.prefetch()

我正在诺基亚5200 诺基亚5130

上测试此应用

可能有什么问题?
请指导我。
以下是我的代码。

public class PlayAudioMidlet extends MIDlet {

private Display display;
AudioPlayer ap;

public void startApp() {

display = Display.getDisplay(this);
ap = new AudioPlayer(this, display);
display.setCurrent(ap); // display a subclass of Form named as AudioPlayer
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}

class AudioPlayer extends Form
implements CommandListener, PlayerListener {

PlayAudioMidlet midlet;
private Display display;
private Command play, stop, exit, forward, backward;
private Player player;

public AudioPlayer(PlayAudioMidlet midlet, Display display) {

super("");
this.midlet = midlet;
this.display = Display.getDisplay(midlet);

play = new Command("Play", Command.OK, 0);
stop = new Command("Stop", Command.STOP, 0);
exit = new Command("Exit", Command.EXIT, 0);

addCommand(play);
addCommand(stop);
addCommand(forward);
addCommand(backward);
addCommand(exit);

setCommandListener(this);
}

public void commandAction(Command c, Displayable d) {

if (c == play) {
try {
//System.out.println(System.currentTimeMillis());
playAudio();
} catch (Exception e) {
e.printStackTrace();
}
} else if (c == stop) {
player.close();
}
}

public void playerUpdate(Player player, String event, Object eventData) {
}

public void playAudio() {
int i = 0;
try {
**//Even this commented line doesn't work
//player = Manager.createPlayer(getClass().getResourceAsStream("/res/alert.mp3"), "audio/mpeg");
player = Manager.createPlayer("file:///E:/Sound/alert1.mp3");**
player.addPlayerListener(this);
// player.setLoopCount(-1);
player.prefetch();
player.realize();
player.start();
} catch (Exception e) {
Alert a = new Alert("");
a.setString("Error "+e.toString());
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);

}
}
} 

2 个答案:

答案 0 :(得分:1)

您最近是否更改了手机的个人资料(即General,Silent等)?进入个人资料的设置,检查是否允许“应用程序音调”。

答案 1 :(得分:1)

我找到了解决方案。

由于我的代码存在问题,设备无法播放任何类型的音乐 所以我刚用工厂设置恢复了我的设备。它正在发挥作用。