0

I have a problem with playing more than 2 sound files in a game I'm developing now in j2me MIDP2 in eclipse. Please advice me the best way for playing multiple "wav" sound files. I created the following method that is called once when the program starts

public void setSound()
        {
            System.out.println("Sound on");
            try {
                p1=Manager.createPlayer(is1, "audio/X-wav");
                p2=Manager.createPlayer(is2, "audio/X-wav");
                p3=Manager.createPlayer(is3, "audio/X-wav");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (MediaException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

and every time I need to play one of the sounds I stop the two other players (to insure that no one of them is running p2.stop(); p3.stop();) and start the third one (p1.start();) and every time I have two players stopped (being in PREFETCHED State) the third one is not running and exceptions are thrown.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Alex
  • 1
  • 1

2 Answers2

1

The Java ME spec is not specific about this, but on actual devices you can usually have only one allocated player at a time, so just stopping a player is not enough. See also this forum post. I found it is a challenge even to deallocate a player properly before playing a new one, so in my own code I resorted to waiting for one sound to end before trying to play a new one.

-1

in j2me there is only one player.More than 1 players are not supported.How execute the sound one sound after another or any other.If u want playing multiple sounds means then u follow the below coding

public class AudioPlayer implements javax.microedition.media.PlayerListener{

Player player;
int count=0;

public void playMedia(){

try{

player = Manager.createPlayer(getClass().getResourceAsStream(audioFiles[count]),"audio/x-amr");
player.addPlayerListener(this);
player.start();

}
catch (Exception e) {
return ;
}
}


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

        //Playing next audio file after completion of current audio.
}

}
SIVAKUMAR.J
  • 4,258
  • 9
  • 45
  • 80