我正在使用 SoundPool 在我的 android 应用程序中播放一些音效。这些声音似乎工作得很好,但我的 LogCat 显示器上出现了以下错误
E/AudioTrack: AudioTrack ctr
E/AudioTrack: start 0x2e6068
E/AudioTrack: Underrun user: 0, server: 0, flags 0003
E/AudioTrack: AudioTrack dtor
E/AudioTrack: stop 0x2d4348
E/AudioTrack: Underrun user: bd00, server: bd00, flags 0002
E/AudioTrack: stop 0x2e6068
声音仍在播放,但有时应用程序会崩溃。
代码片段声音池:
private void setupSounds() {
soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<String, Integer>(16);
// Add all note references into a hashmap with the string that will be attached
soundPoolMap.put("LOWC", soundPool.load(getContext(), R.raw.lowc, 1));
soundPoolMap.put("LOWD", soundPool.load(getContext(), R.raw.lowd, 1));
soundPoolMap.put("LOWE", soundPool.load(getContext(), R.raw.lowe, 1));
soundPoolMap.put("LOWF", soundPool.load(getContext(), R.raw.lowf, 1));
soundPoolMap.put("LOWG", soundPool.load(getContext(), R.raw.lowg, 1));
soundPoolMap.put("LOWA", soundPool.load(getContext(), R.raw.lowa, 1));
soundPoolMap.put("LOWB", soundPool.load(getContext(), R.raw.lowb, 1));
soundPoolMap.put("LOWZ", soundPool.load(getContext(), R.raw.lowz, 1));
soundPoolMap.put("MIDDLEC", soundPool.load(getContext(), R.raw.middlec, 1));
soundPoolMap.put("MIDDLED", soundPool.load(getContext(), R.raw.middled, 1));
soundPoolMap.put("MIDDLEE", soundPool.load(getContext(), R.raw.middlee, 1));
soundPoolMap.put("MIDDLEF", soundPool.load(getContext(), R.raw.middlef, 1));
soundPoolMap.put("MIDDLEG", soundPool.load(getContext(), R.raw.middleg, 1));
soundPoolMap.put("MIDDLEA", soundPool.load(getContext(), R.raw.middlea, 1));
soundPoolMap.put("MIDDLEB", soundPool.load(getContext(), R.raw.middleb, 1));
soundPoolMap.put("MIDDLEZ", soundPool.load(getContext(), R.raw.middlez, 1));
}
这就是我播放声音的地方
soundPool.play(soundPoolMap.get(getSoundFromHashmap(xPos, yPos)), Constants.VOLUME, Constants.VOLUME, 1, 0, 1f);
从我读过的内容来看,这似乎是正确的代码,所以我很难过。任何想法,将不胜感激。