私のSoundManagerクラスは、オーディオにSoundPoolを使用しています。停止するように指示されるまで、1秒オンと2秒オフのループ音が鳴ります。問題は、これが1回実行されると、logcatに「SoundPool:AudioTrackの作成中にエラーが発生しました」というエラーが表示され、「AudioTrack:AudioFlingerはトラックを作成できませんでした。ステータス:-12」というエラーが表示されることです。コードは次のとおりです。なぜこのエラーが発生するのか考えてみてください。
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;
}