Code example for SoundPool

Methods: playstop

0
     * Stop the current sound 
     */ 
    public void stopSound() { 
    	mHandler.removeCallbacks(mPlayNext);
    	mSoundQueue.clear();
        mSoundPool.stop(curStreamId);
        mPlaying = false;
    } 
 
    public void unloadAll() { 
    	stopSound(); 
        if (mSoundPoolMap.size() > 0) {
            for (String key : mSoundPoolMap.keySet()) {
                mSoundPool.unload(mSoundPoolMap.get(key).id);
            } 
        } 
        mSoundPoolMap.clear();   	
    } 
     
    /** 
     * Deallocates the resources and Instance of SoundManager 
     */ 
    public void cleanup() { 
    	unloadAll(); 
        mSoundPool.release();
        mSoundPool = null;
        _instance = null;
    } 
 
    private void playNextSound() { 
    	if (mSoundQueue.isEmpty() != true) {
	    	String key = mSoundQueue.remove(0);
	    	Sound sound = mSoundPoolMap.get(key);
	    	if (sound != null) {
		        float streamVolume = 0.0f;
		        streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		        streamVolume /= mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		         
		        curStreamId = mSoundPool.play(sound.id, streamVolume, streamVolume, 1, 0, 1.0f); 
		        mPlaying = true;
		        mHandler.postDelayed(mPlayNext, sound.time);
	    	} 
	    	else { 
	    		playNextSound();