Code example for SoundPool

Methods: setOnLoadCompleteListener

0
	private HashMap<String, Integer> soundMap;
	private final AssetManager assetManager;
 
	public SoundManager(AssetManager assetManager) {
		this.assetManager = assetManager;
		soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
		soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
			public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
				if (status == 0 && sampleId != 0) {
					if (soundPool.play(sampleId, LEFT_VOLUME, 
							RIGHT_VOLUME, PRIORITY, LOOP, 
								RATE) == STREAM_ERROR) {
						Log.e(LOG_TAG, "Playback error for file with " +
								"soundId " + sampleId);
					} 
				} else { 
					Log.e(LOG_TAG, "Soundpool error, status code: " + status);
				} 
			} 
		});