我正在尝试使用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>
发布于 2019-01-15 19:10:36
将这段代码放在脚本的最开始部分(在Matt戴蒙德的例子中,它也在main.js
中):
window.AudioContext = window.AudioContext || window.webkitAudioContext;
这将独立于您的浏览器加载正确的AudioContext。
发布于 2013-09-14 14:15:32
您的代码在Chrome29中运行良好,您的浏览器支持Web Audio API吗?(http://caniuse.com/audio-api)
我得到了一个"ReferenceError: AudioContext not defined“错误,在使用AudioContext()
而不是webkitAudioContext()
之前,就像您一样使用AudioContext Monkey Patch。确定它已加载,并且不是缓存/硬刷新问题?
https://stackoverflow.com/questions/18674510
复制相似问题