Code example for SoundPool

Methods: loadsetOnLoadCompleteListener

0
		maxVolume = (float) audioManager
				.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		volume = actualVolume / maxVolume;
 
//		loadSounds(); 
		soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 0);
		soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
			@Override 
			public void onLoadComplete(SoundPool soundPool, int sampleId,
					int status) {
				isLoaded = true;
				// play by SoundPool 
				playSound(); 
			} 
		}); 
	} 
	public SoundPool loadSounds() {
		File tempMp3File = getMp3File(activity, word);
		 
		 
		if(tempMp3File == null){
			return null; 
		}// return 
		 
		if(soundPool !=null){	//�Ѿ��½���
			if(idFileMap.size()>=80){
				soundPool.release();
				soundPool =null;
				idFileMap.clear();
				newAsoundPool(); 
				Log.d("�����涨��Ƶ��", "�Ѿ����½���SoundPoll");
			} 
			Log.d("���Ŵ���:"+idFileMap.size(),tempMp3File.getName().substring(0, tempMp3File.getName().length()-4));
			//�˴���Ҫunload,�������治���ظ�ʹ������ID 
			//			soundPool.unload(id);//unload last id 
		}else{			//��һ��ʹ�� 
			newAsoundPool(); 
 
		}//end if 
		filePath = tempMp3File.getAbsolutePath();
		id = soundPool.load(filePath,1);
		//���漸�д����ò��ˣ�Ŀ���ǣ��ظ�ʹ�����е�ID(�Ѿ���������) 
		if(idFileMap.containsKey(filePath)){//�����Ѿ����ڣ���ȡ��ID
			id = idFileMap.get(filePath);
			Log.d("��������id = ", idFileMap.get(filePath)+"");
		}else{									 
			id = soundPool.load(filePath,1);//�����ڣ��������µ�ID���ӵ�MAP
			idFileMap.put(filePath, id);
			Log.d("�½� id = "+id, filePath+"");
		} 
		return soundPool;
	}