Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript mic-recorder-to-mp3仅用于重新编译_Javascript_Audio_Audio Recording - Fatal编程技术网

Javascript mic-recorder-to-mp3仅用于重新编译

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() {

我有一个简单的HTML web元素和一个嵌入式录音机。我希望录音机在加载后自动开始录音。我经历了一些非常奇怪的行为,当我重新编译应用程序时,录音就起作用了。如果我在已经编译的应用程序版本上刷新页面,我会得到一个空的录制缓冲区

以下是我的代码的关键部分:

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(() => {...})
    }
  }