Javascript mic-recorder-to-mp3仅用于重新编译
我有一个简单的HTML web元素和一个嵌入式录音机。我希望录音机在加载后自动开始录音。我经历了一些非常奇怪的行为,当我重新编译应用程序时,录音就起作用了。如果我在已经编译的应用程序版本上刷新页面,我会得到一个空的录制缓冲区 以下是我的代码的关键部分:Javascript mic-recorder-to-mp3仅用于重新编译,javascript,audio,audio-recording,Javascript,Audio,Audio Recording,我有一个简单的HTML web元素和一个嵌入式录音机。我希望录音机在加载后自动开始录音。我经历了一些非常奇怪的行为,当我重新编译应用程序时,录音就起作用了。如果我在已经编译的应用程序版本上刷新页面,我会得到一个空的录制缓冲区 以下是我的代码的关键部分: const MicRecorder = require("mic-recorder-to-mp3"); ... class Microphone extends HTMLElement { constructor() {
const MicRecorder = require("mic-recorder-to-mp3");
...
class Microphone extends HTMLElement {
constructor() {
super();
// Add a shadow DOM
const shadowDOM = this.attachShadow({ mode: "open" });
this.shadowDOM = shadowDOM;
// Render
this.shadowDOM.appendChild(template.content.cloneNode(true));
...
// Bind methods
this.toggleRecord = this.toggleRecord.bind(this);
}
connectedCallback() {
if (this.startRecording) {
this.toggleRecord();
}
}
toggleRecord() {
const recordButton = this.shadowRoot.querySelector("#record-button");
if (this.isRecording()) {
this.recorder
.stop()
.getMp3()
.then(([buffer, blob]) => {...})
} else {
this.recorder
.start()
.then(() => {...})
}
}