Android SoundPool:AudioFlinger错误

时间:2012-12-07 23:10:40

标签: java android multithreading soundpool

我的SoundManager类使用SoundPool作为它的音频。我有一个声音会循环,1秒钟和2秒钟关闭,直到被告知停止。问题是这将执行一次,然后我注意到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;
}

1 个答案:

答案 0 :(得分:0)

Error : AudioTrack: AudioFlinger could not create track, status: -12
属于活动曲目的总数是32,你试图创建另一个曲目 Android只能支持32个曲目名称 你能否查看Obtain Buffer TimeOut等其他错误 请尝试将您的应用程序应用到其他Android设备或检查重启您的设备。