j2me + javax.microedition.midlet.MediaException:不允许声音

发布于 2024-12-13 19:35:14 字数 2162 浏览 0 评论 0原文

我正在尝试播放 MP3 并遇到意外错误。
我在 3 天前测试了我的应用程序

,它在我的设备上运行完美

,但现在即使相同的 jar 文件也给我带来以下错误。

javax.microedition.midlet.MediaException:Sounds not allowed

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

我正在 Nokia 5200Nokia 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);

}
}
} 

I am trying to Play MP3 and getting unexpected errors.
I have tested my app before 3 days

which was working perfect on my device

but now even that same jar file is giving me following error.

javax.microedition.midlet.MediaException:Sounds not allowed

error is coming when it executes this line
player.prefetch()

I am testing this app on Nokia 5200 and Nokia 5130

what could be problem?
Please guide me.
Following is my code.

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);

}
}
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此岸叶落 2024-12-20 19:35:14

您最近是否更改过手机的配置文件(即常规、静音等)?进入您的个人资料设置并检查是否允许“应用程序铃声”。

Have you changed the phone's profile (i.e. General, Silent etc) recently? Go into the settings of your profile and check if the "Application Tones" are allowed.

倾`听者〃 2024-12-20 19:35:14

我找到了解决方案。

由于我的代码中存在一些问题,设备无法播放任何类型的音乐。
所以我只是将我的设备恢复为出厂设置。它正在发挥作用。

I found the solution.

due to some problem in my code, device was not able to play any kind of music.
So I just restored my device with factory settings. And it is working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文