0
我的SoundManager類使用SoundPool作爲其音頻。我有一個聲音會循環,1秒鐘後關閉2秒鐘,直到停止。問題是,這將執行一次,然後我注意到logcat中有一個錯誤,說「SoundPool:創建AudioTrack時出錯」,然後「AudioTrack:AudioFlinger無法創建軌道,狀態:-12」我的代碼如下。任何想法爲什麼我得到這個錯誤?Android SoundPool:AudioFlinger錯誤
public class SoundManager {
public SoundManager(Context c) {
mContext = c;
sp = new SoundPool(1,AudioManager.STREAM_MUSIC,0);
spSound = sp.load(mContext, R.raw.tone4402, 1);
}
public void Tone3(int timer) {
(new Thread(t3)).start();
}
final Runnable t3 = new Runnable() {
public void run() {
if(isPlaying == false) {
isPlaying = true;
Tone3Run();
}
}
};
public static void Tone3Run() {
//1 sec on, 2 sec off, repeat for 2 minute
Log.d("Sound", "Tone3 Playing");
long startTime = System.currentTimeMillis();
long currentTime;
do
{
currentTime = System.currentTimeMillis();
Log.e("Sound Manager", "Time:" + (currentTime - startTime));
temp = sp.play(spSound, currentVolume, currentVolume, 1, -1, (float)1.0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
sp.pause(temp);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while(((currentTime - startTime) < 120000) && (boolStop = false));
sp.release();
sp = new SoundPool(1, 4, 0);
spSound = sp.load(mContext, R.raw.tone4402, 1);
isPlaying = false;
}
'-12'是'ENOMEM',或'內存不足'。 [錯誤代碼](http://www.barricane.com/c-error-codes-include-errno) – Tim
感謝您的支持,能夠解決問題 – Dogz1