我有一個按鈕,當按下時用SoundPool聽起來很短的聲音效果。該文件是一個16K的MP3。
聲音效果適用於數百個按鈕的點擊,但在某些時候,我得到這個錯誤(和聲音不玩了再點擊):SoundPool停止播放
E/AudioFlinger( 34): no more track names available
E/AudioTrack( 904): AudioFlinger could not create track, status: -12
E/SoundPool( 904): Error creating AudioTrack
W/AudioFlinger( 34): write blocked for 81 msecs, 4573 delayed writes, thread
xb3f0
的onCreate:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundpool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
// TODO Auto-generated method stub
loaded = true;
}
});
//save the effect somewhere:
MyUtil.regularSound = soundpool.load(this, R.raw.regular_click,1);
的onClick:
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualVol = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVol = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float vol = actualVol/maxVol;
if (loaded) {
soundpool.play(MyUtil.regularSound,vol,vol,1,0,1f);
}
開始另一個意圖之前:
Intent i = new Intent(con, EndScreen.class);
if (soundpool != null) {
soundpool.release();
soundpool = null;
}
startActivity(i);
我2分錢的價值:可能是因爲soundpool版本尚未處理(GC),並且該插槽在soundpool發佈時仍處於活動狀態。你已經將maxstreams設置爲10.只是一個想法。 – opaque