如何解决Firefox 仅使用 MediaRecorder 记录整个音频输入的开始部分
我正在测试用于记录媒体设备的 MediaRecorder API。我在 CodePen 中创建了一个简单的代码来测试这个。在 Firefox 87 上,当我尝试录制时,只录制了我声音的开头。而在 chrome 上,整个部分都会被记录下来。
<button id='record'>record</button>
<button id='stop'>stop</button>
<audio src="" id='audio' controls></audio>
window.recorder = null;
window.onload = function() {
document.getElementById("record").addEventListener('click',function() {
startRecording();
});
document.getElementById("stop").addEventListener('click',function() {
stop();
});
function startRecording() {
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
window.recorder = new MediaRecorder(stream);
// Set record to <audio> when recording will be finished
window.recorder.addEventListener("dataavailable",(e) => {
console.log(e.data);
document.getElementById("audio").src = URL.createObjectURL(e.data);
});
window.recorder.start();
});
}
function stop() {
window.recorder.stop();
}
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。