【问题标题】:ReferenceError: AudioContext not definedReferenceError:未定义 AudioContext
【发布时间】:2013-09-11 13:00:09
【问题描述】:

我正在尝试使用要求我拥有 AudioContext 的 RecorderJS 库 (https://github.com/mattdiamond/Recorderjs)。但是,当在脚本的最开始声明 AudioContext 时,页面加载时控制台中出现错误,显示“ReferenceError:AudioContext 未定义”。像其他人一样遇到过这样的 AudioContext 问题吗?我已经发布了我的 JS 的 sn-p 和包含所有内容的 HTML。提前致谢!

JS:

var audioContext = new AudioContext();
var audioInput = null, inputPoint = null, audioRecorder = null;

$(document).ready(function(){
    // recording stuff
});

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Recording</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel='stylesheet' type='text/css' href='stylesheet.css'/>
        <script src="http://cwilso.github.io/AudioContext-MonkeyPatch/AudioContextMonkeyPatch.js"></script>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="recorder.js"></script>
        <script src="script.js"></script>
    </head>
    <body>
        <button class="record" type='button'>Record</button>
    </body>
</html>

【问题讨论】:

    标签: javascript html audio audio-recording webkitaudiocontext


    【解决方案1】:

    把它放在脚本的开头(在 Matt Diamond 的示例中,它也在 main.js 中):

    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    

    这会独立于您的浏览器加载正确的 AudioContext。

    【讨论】:

      【解决方案2】:

      您的代码在 Chrome29 中运行良好,您的浏览器是否支持 Web Audio API? (http://caniuse.com/audio-api)

      在像您一样使用 AudioContext Monkey Patch 之前,我使用 AudioContext() 而不是 webkitAudioContext() 收到“ReferenceError: AudioContext not defined”错误。确定它已加载,而不是缓存/硬刷新问题?

      【讨论】:

        猜你喜欢
        • 2012-08-24
        • 2015-10-04
        • 2017-04-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多