you can see code
public class SoundManager {
public static int SOUNDPOOLSND_MENU_BTN = 0;
public static int SOUNDPOOLSND_WIN = 1;
public static int SOUNDPOOLSND_LOOSE = 2;
public static int SOUNDPOOLSND_DRAW = 3;
public static int SOUNDPOOLSND_TICK1 = 4;
public static int SOUNDPOOLSND_TICK2 = 5;
public static int SOUNDPOOLSND_OUT_OF_TIME = 6;
public static int SOUNDPOOLSND_HISCORE = 7;
public static int SOUNDPOOLSND_CORRECT_LETTER = 8;
public static boolean isSoundTurnedOff;
private static SoundManager mSoundManager;
private SoundPool mSoundPool;
private SparseArray<Integer> mSoundPoolMap;
private AudioManager mAudioManager;
public static final int maxSounds = 4;
public static SoundManager getInstance(Context context) {
if (mSoundManager == null) {
mSoundManager = new SoundManager(context);
}
return mSoundManager;
}
public SoundManager(Context mContext) {
mAudioManager = (AudioManager) mContext
.getSystemService(Context.AUDIO_SERVICE);
mSoundPool = new SoundPool(maxSounds, AudioManager.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
boolean loaded = true;
}
});
mSoundPoolMap = new SparseArray<Integer>();
mSoundPoolMap.put(SOUNDPOOLSND_MENU_BTN,
mSoundPool.load(mContext, R.raw.rain, 0));
mSoundPoolMap.put(SOUNDPOOLSND_WIN,
mSoundPool.load(mContext, R.raw.nature, 1));
mSoundPoolMap.put(SOUNDPOOLSND_LOOSE,
mSoundPool.load(mContext, R.raw.piano, 2));
mSoundPoolMap.put(SOUNDPOOLSND_TICK1,
mSoundPool.load(mContext, R.raw.relax, 3));
mSoundPoolMap.put(SOUNDPOOLSND_TICK2,
mSoundPool.load(mContext, R.raw.storm, 4));
// testing simultaneous playing
int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(0), streamVolume, streamVolume, 1,
0, 1f);
mSoundPool.play(mSoundPoolMap.get(1), streamVolume, streamVolume, 1, 0,
1f);
mSoundPool.play(mSoundPoolMap.get(2), streamVolume, streamVolume, 1, 0,
1f);
}
public void playSound(int index) {
if (isSoundTurnedOff)
return;
int streamVolume = mAudioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume,
1, 0, 1f);
}
public static void clear() {
if (mSoundManager != null) {
mSoundManager.mSoundPool = null;
mSoundManager.mAudioManager = null;
mSoundManager.mSoundPoolMap = null;
}
mSoundManager = null;
}
}