我的SoundManager类使用SoundPool作为它的音频。我有一个声音会循环,1秒开,2秒关,直到被告知停止。问题是,这将执行一次,然后我注意到日志中的一个错误,说"SoundPool: error creating AudioTrack“,然后是"AudioTrack: AudioFlinger and‘t create track,status:-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;
}发布于 2013-05-05 01:04:07
Error : AudioTrack: AudioFlinger could not create track, status: -12
属于活动曲目总数为32,并且您正在尝试创建另一个曲目。
Android只能支持32个曲目名称。
您可以检查其他错误,如Obtain Buffer TimeOut。
请在其他Android设备上试用您的应用程序,或检查是否重新启动您的设备。
https://stackoverflow.com/questions/13772483
复制相似问题