javascript - 如果在 FireFox 上仍然不好,如何修复与/setTimeout 的网络音频时间关系

标签 javascript firefox html5-audio web-audio-api

我正在创建一个音乐排序应用程序和 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)来查看正在运行的应用程序。

A JSfiddle is available here

如果你先用 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/

相关文章:

Javascript 问题

html - 图像在 Firefox 上的行为不同

javascript - 打开本地文件时如何绕过 document.domain 限制?

javascript - 通过选择具有类的元素来获取下一个元素

javascript - MediaRecorder - 是否可以同时录制和播放?

javascript - 如何检查音频是否为空?

html - 移动浏览器无法为 <audio> 标签加载 base64 数据 uri

javascript - 将 css 设置为父子大小

javascript - new Array() 与 Object.create(Array.prototype)

javascript - jQuery 验证引擎不适用于 Bootstrap Select 插件