我正在创建一个音乐排序应用程序和 I used the methodology explained in this article 。然而,当我在 Chrome 中玩我的项目时,一切都很好,当我使用 Firefox 时,时间不稳定,与单独使用 setTimeout 或 SetInterval 半相似。
我的调度程序代码如下。 The JS file can be viewed here 。可以通过转到与 js 文件相同的链接并将“javascript/index.js”替换为“index.html”(Stackoverflow 不允许我直接发布该 url)来查看正在运行的应用程序。
如果你先用 Chrome 听,然后用 Firefox 听,你就能听到区别,后者不好。我不确定这是我的错还是 Firefox 就是这样。
function scheduleFutureNote() {
while (futureNote <= audioContext.currentTime + 0.10) { //_________When you've gotten within a Nth of a second is when you schedule the note
playFutureNote(futureNote);
futureNote += (60 / tempo) / 4;
}
if (timer) {
timer = window.setTimeout(scheduleFutureNote, 0.10); //__________sleep for n milliseconds...then check to see if we're close to next note.
} else {
timer === false
}
};
最佳答案
window.setTimeout() 以毫秒为单位,而不是秒。您需要 setTimeout(scheduleFutureNode, 100)。
关于javascript - 如果在 FireFox 上仍然不好,如何修复与/setTimeout 的网络音频时间关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27375146/