我正在尝试使用RecorderJS库(https://github.com/mattdiamond/Recorderjs),这需要我有一个AudioContext。但是,当我在脚本的最开头声明AudioContext时,我在页面加载的控制台中收到一条错误,指出“ReferenceError:AudioContext未定义”。正如其他任何人遇到的AudioContext问题一样吗?我已经发布了我的JS片段和包含所有内容的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>
您的代码在Chrome29中运行正常,您的浏览器是否支持Web Audio API? (http://caniuse.com/audio-api)
在使用AudioContext Monkey Patch之前,我使用AudioContext()
而不是webkitAudioContext()
得到了“ReferenceError:AudioContext not defined”错误。当然它已加载而不是缓存/硬刷新问题?
把它放在脚本的最开头(在Matt Diamond的例子中也是main.js
):
window.AudioContext = window.AudioContext || window.webkitAudioContext;
这将加载与您的浏览器无关的正确AudioContext。