Вопрос

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

}
}
} 
Это было полезно?

Решение 2

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top