Code example for SoundPool

Methods: loadplaysetOnLoadCompleteListener

0
 
	public void load(File file ,final boolean playAfterLoaded) {
		 
		if (!file.exists()) return;
		 
   		_soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
   			public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
   				_soundIsLoading=true;
   				onLoad(); 
   				if (playAfterLoaded) Play();
   			} 
   		}); 
 
	   	if (_soundsMap.containsKey(file.getPath())) {
			_currentSoundID = _soundsMap.get(file.getPath());
			RePlay(); 
		} else { 
			_currentSoundID = _soundPool.load(file.getPath(), 1);
			_soundsMap.put(file.getPath(),_currentSoundID);
			_soundIsLoading = true;
		} 
	} 
 
	public void RePlay() { 
		_soundIsLoading= true;
		Play(); 
	} 
	 
	public void Play() { 
			if (_soundIsLoading)	{
				    // Getting the user sound settings 
				      AudioManager audioManager = (AudioManager) _context.getSystemService(Context.AUDIO_SERVICE);
				      float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_RING);
				      float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
				      float volume = actualVolume / maxVolume;
				  
					_soundPool.play(_currentSoundID, volume, volume, 1, 0, 1f);
				} 
 
	} 
	 
	public void onLoad(){} 
Connect your IDE to all the code out there  Get Codota for Java