您好,我发现这个脚本可以让您在浏览器中录制音频文件,因此它适用于除 Edge 之外的大多数浏览器。所以在页面加载时我得到这个错误。
错误 0:未定义“MediaRecorder”
当我按下录制按钮时,我得到了这个错误。
0: 'rec' 未定义
然后当我按下停止时,我得到了这个错误。
0: 'rec' 未定义
所以我不知道如何让它在 Edge 上工作。
我试图弄乱它,但我仍然不知道怎么弄,而且我在网上找不到任何可以帮助我解决这个问题的资源。
这是代码
navigator.mediaDevices.getUserMedia({
audio: true
})
.then(stream => {
handlerFunction(stream)
})
function handlerFunction(stream) {
rec = new MediaRecorder(stream);
rec.ondataavailable = e => {
audioChunks.push(e.data);
if (rec.state == "inactive") {
let blob = new Blob(audioChunks, {
type: 'audio/mpeg-3'
});
recordedAudio.src = URL.createObjectURL(blob);
recordedAudio.controls = true;
recordedAudio.autoplay = true;
sendData(blob)
}
}
}
function sendData(data) {}
record.onclick = e => {
console.log('I was clicked')
record.disabled = true;
record.style.backgroundColor = "blue"
stopRecord.disabled = false;
audioChunks = [];
rec.start();
}
stopRecord.onclick = e => {
console.log("I was clicked")
record.disabled = false;
stop.disabled = true;
record.style.backgroundColor = "red"
rec.stop();
}
#record {
background-color: red;
/* Green */
border-width: medium;
border-color: black;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
max-width: 50%;
max-height: 15%;
border-radius: 50%;
left: 100px;
right: 100px;
position: relative;
}
#stopRecord {
background-color: green;
/* Green */
border-width: medium;
border-color: black;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
max-width: 50%;
max-height: 15%;
border-radius: 50%;
left: 100px;
right: 100px;
position: relative;
}
h2 {
left: 100px;
position: relative;
}
慕田峪9158850
素胚勾勒不出你
慕勒3428872
相关分类