he 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);
}
}
// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if (!mKillSoundQueue.isEmpty()) {
mSoundPool.stop(mKillSoundQueue
.firstElement());
}
}
}, delay);
}
/**
* Loads the various sound assets
* @param locale the load to load audio files
*/
public void loadSounds(String locale)
throws SAXException, IOException,
ParserConfigurationException {
Log.d("load locale", locale);
this.locale = locale;
AssetFileDescriptor afd;
Map audioFiles = util
.getAudioFileConfig(locale,
mContext.getAssets());
for (String key : audioFiles.keySet()) {
afd = mContext.getAssets().openFd(
audioFiles.get(key));
addSound(key, afd);
}
}
/**
* Stop a Sound
*
* @param index - index of the sound to be stopped
*/
public void stopSound(int index) {
mSoundPool.stop(mSoundPoolMap.get(index));
}
/**
* Deallocates the resources and Instance of SoundManager
*/
public void cleanup() {
mSoundPool.release();
mSoundPool = null;
mSoundPoolMap.clear();
mAudioManager.unloadSoundEffects();
_instance = null;
}
/**
* unload all resource in the sound pool
* support for user change VoiceLanguage or Locale or user close th