MediaRecorder - 暂停和恢复事件在 Firefox 中不起作用
MediaRecorder - The Pause and resume events don't work in Firefox
我正在努力思考 MediaRecorder API,所以我编写了一个简单的 Web 应用程序,可以启动、暂停、恢复和停止录音。代码似乎工作正常,直到我在 Firefox(最新版本)中测试它。
Javascript代码:
var mediaRecorder = null,
constraints = { audio: true };
function onSuccess( stream ) {
mediaRecorder = new MediaRecorder( stream );
function getStatus() {
alert('The mediaRecorder is ' + mediaRecorder.state);
}
mediaRecorder.onstart = getStatus;
mediaRecorder.onpause = getStatus;
mediaRecorder.onresume = getStatus;
mediaRecorder.onstop = getStatus;
}
var onError = function(err) {
console.log('Error: ' + err);
}
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
Html代码:
<button type="button" onclick="mediaRecorder.start()">Start</button>
<button type="button" onclick="mediaRecorder.pause()">Pause</button>
<button type="button" onclick="mediaRecorder.resume()">Resume</button>
<button type="button" onclick="mediaRecorder.stop()">Stop</button>
我发现,在 Firefox 中,当单击暂停时,mediaRecorder 实际上已暂停,但它不会触发暂停事件 ( onpause ),恢复也是如此。
问题:有办法解决这个问题吗?
不幸的是,这是一个 bug in Mozilla Firefox, and as a workaround, I found this awesome cross-browser library and it worked for me like a charm : Audrec
我正在努力思考 MediaRecorder API,所以我编写了一个简单的 Web 应用程序,可以启动、暂停、恢复和停止录音。代码似乎工作正常,直到我在 Firefox(最新版本)中测试它。
Javascript代码:
var mediaRecorder = null,
constraints = { audio: true };
function onSuccess( stream ) {
mediaRecorder = new MediaRecorder( stream );
function getStatus() {
alert('The mediaRecorder is ' + mediaRecorder.state);
}
mediaRecorder.onstart = getStatus;
mediaRecorder.onpause = getStatus;
mediaRecorder.onresume = getStatus;
mediaRecorder.onstop = getStatus;
}
var onError = function(err) {
console.log('Error: ' + err);
}
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
Html代码:
<button type="button" onclick="mediaRecorder.start()">Start</button>
<button type="button" onclick="mediaRecorder.pause()">Pause</button>
<button type="button" onclick="mediaRecorder.resume()">Resume</button>
<button type="button" onclick="mediaRecorder.stop()">Stop</button>
我发现,在 Firefox 中,当单击暂停时,mediaRecorder 实际上已暂停,但它不会触发暂停事件 ( onpause ),恢复也是如此。
问题:有办法解决这个问题吗?
不幸的是,这是一个 bug in Mozilla Firefox, and as a workaround, I found this awesome cross-browser library and it worked for me like a charm : Audrec