thanks to Tim, using Thread for the game seems to have successfully fixed the problem.
Topic
package org.racenet.racesow.threads; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import org.racenet.racesow.models.SoundItem; import android.media.SoundPool; public class SoundThread extends Thread { private SoundPool soundPool; public BlockingQueue<SoundItem> sounds = new LinkedBlockingQueue<SoundItem>(); public boolean stop = false; public SoundThread(SoundPool soundPool) { this.soundPool = soundPool; } public void unloadSound(int soundID) { this.soundPool.unload(soundID); } @Override public void run() { try { SoundItem item; while (!this.stop) { item = this.sounds.take(); if (item.stop) { this.stop = true; break; } this.soundPool.play(item.soundID, item.volume, item.volume, 0, 0, 1); } } catch (InterruptedException e) {} } }
Sounditem
package org.racenet.racesow.models; public class SoundItem { public soundID; public volume; public stop = false; public SoundItem(int soundID, float volume) { this.soundID = soundID; this.volume = volume; } public SoundItem(boolean stop) { this.stop = stop; } }
source share