I want to play a existed sound file (*.wav) which I have already put it into res folder. The problem is that the piece of code works properly in simulator (Sun java WTK 2.5.2 for CLDC). Then I created package and installed the app into my N97, it doesn't work at all. No error message, just give no response.
Advanced thx for any help.
This is MIDlet that invokes the code aboveCode:import java.io.InputStream; import javax.microedition.media.Manager; import javax.microedition.media.MediaException; import javax.microedition.media.Player; public class PlayMusic { public InputStream is; public Player player; public PlayMusic() { try{ is = getClass().getResourceAsStream("/q.wav"); player = Manager.createPlayer(is, "audio/x-wav"); }catch (Exception e) { e.printStackTrace(); } } public void sound(){ try { player.realize(); player.prefetch(); player.start(); } catch (MediaException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Code:import javax.microedition.media.MediaException; import javax.microedition.media.Player; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class test extends MIDlet { public test(){ } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } protected void pauseApp() { // TODO Auto-generated method stub } protected void startApp() throws MIDletStateChangeException { // TODO Auto-generated method stub PlayMusic pm=new PlayMusic(); pm.sound(); // TODO Auto-generated catch block } }

Reply With Quote


