1 answer
android.media.SoundPool
The designer indicated how many sounds can be played simultaneously.
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
Using the load
method, we loaded the necessary sounds, got their identifiers.
soundID1 = soundPool.load(this, R.raw.sound1, 1); soundID2 = soundPool.load(this, R.raw.sound2, 1);
Waited for the loading of sounds
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { loaded += 1; } });
You can play sounds:
if( loaded > 1 ) { soundPool.play(soundID1, 1f, 1f, 1, 0, 1f); soundPool.play(soundID2, 1f, 1f, 1, 0, 1f); }
|