I would like to learn how to use soundpool method. I would like you to show me a very simple example that run 2 sounds.
private final int NUMBER_OF_SIMULTANEOUS_SOUNDS = 5;
private final float LEFT_VOLUME_VALUE = 1.0f;
private final float RIGHT_VOLUME_VALUE = 1.0f;
private final int MUSIC_LOOP = 0;
private final int SOUND_PLAY_PRIORITY = 0;
private final float PLAY_RATE= 1.0f;
SoundPool soundPool;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
soundPool= new SoundPool.Builder()
.setMaxStreams(NUMBER_OF_SIMULTANEOUS_SOUNDS)
.build();
} else {
// Deprecated way of creating a SoundPool before Android API 21.
soundPool= new SoundPool(NUMBER_OF_SIMULTANEOUS_SOUNDS, AudioManager.STREAM_MUSIC, 0);
}
int soundId = soundPool.load(getApplicationContext(), R.raw.sound_1, 1);
soundPool.play(soundId , LEFT_VOLUME_VALUE , RIGHT_VOLUME_VALUE, SOUND_PLAY_PRIORITY , MUSIC_LOOP ,PLAY_RATE);