Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Developer
Posts: 14
Registered: ‎09-15-2009
My Device: Not Specified

multiple musicPlayer advice

I'm using a key press to play a sound:



  public boolean keyChar(char key, int status, int time) {
          if(key == Characters.LATIN_SMALL_LETTER_Q)
              {try {
  			} catch (MediaException e) {



I prefetch the musicPlayer when the program starts so the audio is ready when I press the key:


		try {
        InputStream in1 = getClass().getResourceAsStream("/fire.wav");            
        musicPlayer1 = javax.microedition.media.Manager.createPlayer(in1, "audio/x-wav");
        } catch (Exception e){
            Dialog.alert("Sound Error");

 The sound file is only 2 seconds long.



When I I push the button once it plays perfectly, and if I wait for it to finish I can hit the key again and it will also play perfectly.  If I push the button again before the musicPlayer is finished playing the sound, nothing will happen.  This keypress is a a firebutton for a game, so I need it to make the sound rapidly, even if the first one isnt finished playing.  IE I need it to be able to run multiple musicPlayers on top of each other to play the same sound effect every time you hit the key.  Is this attainable?  If so how would you go about handling multiple keypresses?

Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: multiple musicPlayer advice

User setmediatime to set the pointer back to beginning before play.