2011-11-05 30 views
0

我想播放MP3並獲取意外的錯誤。
我已經3天前j2me + javax.microedition.midlet.MediaException:聲音不允許

這是完美的工作我的設備

上,但現在即使是同一個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); 

} 
} 
} 

回答

1

我找到了解決方案。

由於我的代碼存在一些問題,設備無法播放任何類型的音樂。
所以我剛恢復我的設備出廠設置。它正在工作。

1

您最近是否更改了手機的配置文件(即General,Silent等)?進入你的配置文件的設置,並檢查是否允許「應用音調」。

+0

不,我沒有改變它們,所有的音調都是允許的。 – Mihir