当我点击按钮在我的应用程序上播放声音时,但保持点击一会儿不再播放。也许这是内存问题?你能解决我的问题吗?这里通过的Soundpool实现播放声音:当我点击按钮,我叫玩儿法:和播放方法的工作后台线程SoundPool在点击几次后不会播放声音
private void play(int resId) {
soundPool = buildBeforeAPI21();//TODO: refactor with deprecated constructor
soundPool.load(activity, Integer.parseInt(resId), 1);
}
public SoundPool buildBeforeAPI21() {
if (soundPool == null) {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
if (status == 0) {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
}
}
});
}
return soundPool;
}
你的点击处理程序在哪里?你如何触发声音播放?你每次都在建造一个新的SoundPool吗?如果是这样,我会建议保留一个实例,并在需要时重复使用它来播放音效,而不是构建一个新实例。 – kcoppock
是的,我只使用一个咒诅 – nAkhmedov