2012-09-24 109 views
0

我有一個按鈕,當按下時用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); 
+1

我2分錢的價值:可能是因爲soundpool版本尚未處理(GC),並且該插槽在soundpool發佈時仍處於活動狀態。你已經將maxstreams設置爲10.只是一個想法。 – opaque

回答

0

我得到相同的錯誤。我做的事情是試圖重新取樣軌道,將其轉換成OGG格式和質量更改爲0這個我做了所有與Audacity

0

你試試代碼吧:這裏

/* 
    private SoundPool mSoundPool; 
    private SparseArray<Integer> mSoundPoolMap; 
    private AudioManager mAudioManager; 
    */ 
    public static void clear() { 
     if (mSoundManager != null) { 
      mSoundManager.mSoundPool = null; 
      mSoundManager.mAudioManager = null; 
      mSoundManager.mSoundPoolMap = null; 
     } 
     mSoundManager = null; 
    } 
2

我只花了幾個小時有同樣的問題。

-12錯誤表示分配給應用程序的聲音內存不足。使用.finish()不會釋放SoundPool的內存。您必須使用.release()

在我的應用我有一個soundPool.release()上的onclick方法開始下一個活動,

更改聲音格式對我也沒有工作。