开发者

Using SoundPool to play clips in succession

I have created a开发者_StackOverflow game for Android Tablets where the player is solving simple math problems. I am working on making the game read each problem aloud. I have sound clip recordings of all of the numbers 0-9 and 20,30,40 etc.. With all of these sound clips I should be able to "mix and match" them to read any possible problem aloud. This is my current sayProblem() method:

    private void sayProblem() {
    if(soundBtn.isChecked() == true){
        Runnable sayRun = new Runnable() {
            public void run(){
                while(sp.play(numberClips[firstOperand - 1], 1, 1, 5, 0, 1) == 0);
                Log.i(myTag, "FirstOp said");
                while(sp.play(signClips[CURRENT_TYPE], 1, 1, 4, 0, 1) == 0);
                Log.i(myTag, "sign said");
                while(sp.play(numberClips[secondOperand - 1], 1, 1, 3, 0, 1) == 0);
                Log.i(myTag, "2ndOp said");
            }
        };

        Thread sayThread = new Thread(sayRun);
        sayThread.start();
    }
}

This works some of the time to read the problem correctly but sometimes there will be really long delays between the 3 different clips that go together to make up a problem. When it works correctly it comes out like this: "one plus three", when it is incorrect it comes out like this:

"one .............................plus...........................three" where the periods represent long pauses of varying lengths.

I imagine using a while loop to keep calling sp.play() is not the correct way to get it to play three sound clips in succession but it is the only thing that has even gotten me close.

Can anyone help me out with using SoundPool (or anything else) to play three clips in succession more consistently?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜