×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    7

    Play more sound at the same time in J2ME

    Hello everyone!
    I'm devenloping a game in J2ME for S40 5th edition. In my game, i want to play a music in the background and sound effect when i press a key so this's a class called Sound made to play.
    public class Sound extends Thread implements PlayerListener{
    private Player player;
    private Thread t;
    public Sound(String file){

    try{
    InputStream is= this.getClass().getResourceAsStream(file);
    String ctype=gettype(file);
    player= Manager.createPlayer(is ,ctype);
    player.realize();
    player.prefetch();


    player.addPlayerListener(this);

    } catch (IOException ioe) {
    } catch (MediaException me) { }
    }
    public void run(){
    try {

    player.start();
    } catch (MediaException me) {}
    }
    public void PlayLoop(){
    try {
    player.setLoopCount(-1);
    player.start();
    } catch (MediaException me) {}
    }
    public void Stop(){
    try {
    player.stop();
    } catch(MediaException me) { }
    }
    public void Close(){
    player.close();
    }
    private static String gettype(String url){
    String type=null;
    try
    {
    // some simple test for the content type
    if (url.endsWith("wav")) {
    type = "audio/x-wav";
    } else if (url.endsWith("jts")) {
    type = "audio/x-tone-seq";
    } else if (url.endsWith("mid")) {
    type = "audio/midi";
    } else {
    throw new Exception("Cannot guess content type from URL: " + url);
    }

    }
    catch(Exception e){}
    return type;
    }
    public void playerUpdate(Player player, String string, Object o) {
    throw new UnsupportedOperationException("Not supported yet.");
    }
    }
    I define : sound=new Sound("/backGround.wav"); and call sound.PlayLoop(); to play music in the background, it's running so well. In keypress event, i create a new thread: new Sound("/click.wav").start(); in order to play a effect music but the result isn't good. It has a silent moment bettwen two sounds. It seems the player can't play two sounds at the same time. How can i do in this situation? Please help me. Thanks for all.

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Play more sound at the same time in J2ME

    Hi hat0203, Welcome to Nokia Developer Discussion Boards !!

    Can you please try in the device the System Property "supports.mixing " A query for whether audio mixing is supported. The string returned is either "true" or "false". If mixing is supported, the following conditions are true:
    At least two tones can be played with Manager.playTone simultaneously.
    Manager.playTone can be used at the same time when at least one Player is playing back audio.
    At least two Players can be used to play back audio simultaneously.

    More info http://library.developer.nokia.com/t...69%6e%67%22%20

    Regards
    Gopal

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    7

    Re: Play more sound at the same time in J2ME

    Thanks to balagopalks!
    I used "System.getProperty("supports.mixing")" and got the answer is true. So what kind of this situation? The sound effect just plays several times and after that it doesn't play .

  4. #4
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Play more sound at the same time in J2ME

    Since you got 'true' for 'supports.mixing', as I mentioned above At least two tones can be played with Manager.playTone simultaneously. Manager.playTone can be used at the same time when at least one Player is playing back audio. At least two Players can be used to play back audio simultaneously.

    Is the player already in PREFETCHED state ? If the player is already in PREFETCHED state, it could help to avoid any delay to start the player.

    Regards
    Gopal

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Play more sound at the same time in J2ME

    Also make sure that you are creating the two instances for the two sounds files. Sharing the code snippets for this can be recommended.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. How to play vibration and sound at the same time?
    By huimin1130 in forum Symbian
    Replies: 2
    Last Post: 2010-05-26, 15:28
  2. Cannot play mid and wav sound at the same time on Nokia N96.
    By Ishnu_Blue in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2008-08-26, 11:14
  3. Play 2 or more sound at same time
    By rudycandrasantoso in forum Symbian
    Replies: 1
    Last Post: 2004-06-06, 17:57
  4. Replies: 0
    Last Post: 2003-12-29, 06:31
  5. Replies: 0
    Last Post: 2003-12-29, 06:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×