int soundId = mSoundPool.play(
mSoundPoolMap.get(key), streamVolume,
streamVolume, 1, 0, rate);
mKillSoundQueue.add(soundId);
// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if (!mKillSoundQueue.isEmpty()) {
mSoundPool.stop(mKillSoundQueue
.firstElement());
}
}
}, delay);
}
/**
*
* @param key the key in the map
*/
public void playLoopedSound(String key) {
int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/ mAudioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int soundId = mSoundPool.play(
mSoundPoolMap.get(key), streamVolume,
streamVolume, 1, -1, rate);
mKillSoundQueue.add(soundId);
// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if (!mKillSoundQueue.isEmpty()) {
mSoundPool.stop(mKillSoundQueue
.firstElement());
}
}
}, delay);
}
/**
* play the sounds have loaded in SoundPool
* @param keys the files key stored in the map
* @throws InterruptedException
*/
public void playMutilSounds(String keys[])
throws InterruptedException {
int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume
/ mAudioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
for (String key : keys) {
Log.d("playMutilSounds", key);
if (mSoundPoolMap.containsKey(key)) {
int soundId = mSoundPool.play(
mSoundPoolMap.get(key),
streamVolume, streamVolume, 1, 0,
rate);
//sleep for a while for SoundPool play
Thread.sleep(seperateTime);
mKillSoundQueue.add(soundId);
}
}