Code example for SparseArray

Methods: get, put, remove

0
	    mLoadComplete = new SparseArray<Boolean>();
	    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener(){
 
			public void onLoadComplete(SoundPool soundPool, int sampleId,
					int status) {
				if (mLoadComplete.get(sampleId) != null){
					mLoadComplete.remove(sampleId);
				} 
				mLoadComplete.put(sampleId, true);
				 
				if (delayPlay){
					if (delayLooped){
						playLoopedSound(sampleId);
					}else{ 
						playSound(sampleId);
					} 
				} 
			} 
			 
	    }); 
	    delayPlay = false;
		delayLooped = false;
	} 
	 
	/** 
	 * load sound from resources 
	 * @param index - individual index of loading sound 
	 * @param SoundID - identificator in the system resources R.raw.sound 
	 */ 
	public void addSound(int index, int SoundID)
	{ 
		int sampleId = mSoundPool.load(mContext, SoundID, 1);
	    mSoundPoolMap.put(index, sampleId);
	} 
	 
	/** 
	 * set volume of sound index 
	 * @param index - individual index of loading sound 
	 * @param volume - volume of sound 0..1 
	 */ 
	public void setPlaySoundVolume(int index, float volume){
		if (mVolumeMap.get(index) != null){
			mVolumeMap.remove(index);
		} 
		mVolumeMap.put(index, volume);
	} 
	 
	/** 
	 * play preveously loaded sound 
	 * @param index - individual index of loading sound 
	 */ 
	public void playSound(int index)
	{ 
		delayPlay	= true;
		delayLooped	= false;
		if (mSoundPoolMap.get(index) != null){
			if (	mLoadComplete.get(mSoundPoolMap.get(index)) != null
				 && mLoadComplete.get(mSoundPoolMap.get(index))){
				 
				float streamVolume = 1;
				if (mVolumeMap.get(index) != null){
					streamVolume = mVolumeMap.get(index);
				}