我正在写一个教孩子们数数的机器人游戏。指令通过声音剪辑被读给玩家,这些声音剪辑被放在一起形成句子(例如,“地方”,“一个”,“牛”,“在”,“谷仓”。当涉及到延迟时,这需要一定的可靠性,以便指令流听起来很自然。
目前我使用的是MediaPlayer,在OnCompletionListener中播放每个声音。每个声音都有它自己的MediaPlayer,它是在开始播放任何声音之前创建和准备的(为了减少延迟)-但在第一次播放每个声音之前,我仍然会得到一个显着的延迟(第二次似乎发生了某种缓存,它工作得很好)。
声音不是很多,而且非常短,它可能会在SoundPool上工作得更好,但是SoundPool没有办法知道音频何时完成,因此没有选择。
有没有人有类似问题的经验和可行的解决方案?
发布于 2012-08-07 17:50:57
我在OnCompletionListener中使用过handler,它可以很好地在两个声音之间提供延迟。
这边请,
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);
}
});https://stackoverflow.com/questions/11842876
复制相似问题