我正在编写一个教 child 数数的android游戏。通过组合成句子的声音片段(例如“Place”,“one”,“cow”,“in the”,“barn”)将指令读取给玩家。这需要一定的可靠性。延迟,使指令的流程听起来自然。
当前,我正在使用MediaPlayer,在OnCompletionListener中播放每种声音。每个声音都有它自己的MediaPlayer,它是在开始播放任何声音之前创建和准备的(以减少延迟)-但是在第一次播放每个声音之前,我仍然会遇到很大的延迟(第二次似乎是某种缓存了)发生,并且工作正常)。
声音不是很多而且很短,它可能与SoundPool一起使用会更好,但是SoundPool无法知道音频何时完成,因此无法选择。
有没有人有过类似问题的经验和可行的解决方案?
最佳答案
我已经将handler
和OnCompletionListener
一起使用了,这对我来说可以很好地在两种声音之间提供延迟。
这条路,
CommonMethod.player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// /will use count and loop as per number of
// repetition chosen.
handler.postDelayed(new Runnable() {
public void run() {
if (counter >= limit) {
CommonMethod.player.stop();
} else {
CommonMethod.player.start();
}
counter++;
}
}, 3000);
}
});
关于android - 在Android上可靠地顺序播放音频,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11842876/