Help: Cant play multiple sound simultaneously with SoundPool

All your problems with Audio, Video and Images.

Help: Cant play multiple sound simultaneously with SoundPool

Postby jackzobin » Tue Apr 13, 2010 6:38 am

I am unable to use the following to code to play multiple sounds/beeps simultaneously. In my onclicklistener I have added ... public void onClick(View v) { mSoundManager.playSound(1); mSoundManager.playSound(2); } ... But this plays only one sound at a time, sound with index 1 followed by sound with index 2.

How can I play atleast 2 sounds simultaneously using this code whenever there is an onClick() event?


Code: Select all
public class SoundManager {
   
   private  SoundPool mSoundPool;
   private  HashMap<Integer, Integer> mSoundPoolMap;
   private  AudioManager  mAudioManager;
   private  Context mContext;
   
   
   public SoundManager()
   {
      
   }
      
   public void initSounds(Context theContext) {
       mContext = theContext;
        mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
        mSoundPoolMap = new HashMap<Integer, Integer>();
        mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);         
   }
   
   public void addSound(int Index,int SoundID)
   {
      mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));
   }
   
   public void playSound(int index) {
      
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
   }
   
   public void playLoopedSound(int index) {
      
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f);
   }
   
}
jackzobin
Freshman
Freshman
 
Posts: 2
Joined: Wed Jan 20, 2010 12:35 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 20 guests