Javascript getUserMedia在Firefox上出现错误,但在Chrome上会自动失败
完整Js代码Javascript getUserMedia在Firefox上出现错误,但在Chrome上会自动失败,javascript,google-chrome,firefox,html5-audio,Javascript,Google Chrome,Firefox,Html5 Audio,完整Js代码 navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); var session = { au
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
var session = {
audio: true,
video: false
};
var recordRTC = null;
navigator.getUserMedia(session, initializeRecorder, onError);
function initializeRecorder(stream) {
console.log ("init Recorder");
var audioContext = window.AudioContext;
var context = new audioContext();
var audioInput = context.createMediaStreamSource(stream);
var bufferSize = 2048;
// create a javascript node
var recorder = context.createJavaScriptNode(bufferSize, 1, 1);
// specify the processing function
recorder.onaudioprocess = recorderProcess;
// connect stream to our recorder
audioInput.connect(recorder);
// connect our recorder to the previous destination
recorder.connect(context.destination);
}
function recorderProcess(e) {
var left = e.inputBuffer.getChannelData(0);
// window.Stream.write(convertFloat32ToInt16(left));
}
function onError(errorText)
{
console.log (errorText);
}
加载此页面时,Firefox会执行getUserMedia的OneError回调。错误表明:
NotFoundError:在此处找不到对象
相反,Chrome什么也不做
FF和Chrome都没有向我申请使用麦克风的许可。为什么?您需要从http(s)协议运行页面。如果您从文件运行它://安全限制生效 此外,在Chrome
AudioContext中,前缀为
,因此您需要更改此行:
var audioContext = window.AudioContext;
到
此外,它已过时。考虑使用,
(最终,
ScriptProcessorNode
也将被替换为——虽然还没有在任何浏览器中实现,但需要注意的是以后要注意)。我无法重现您的问题:。也许您正试图在文件:
页面上执行此操作?如果是,这可能是的副本。(此外,您应该使用。)
var audioContext = window.AudioContext || window.webkitAudioContext;