Friday 27 November 2020

Original audio of tab gets muted while using chrome.tabCapture.capture() and MediaRecorder()

when i use chrome.tabCapture.capture() with MediaRecorder API to record stream original audio of tabs which i am capturing gets muted but the audio comes OK in recorded stream, i want the audio in the tab to run normally ....

class Recorder {
  constructor(onChunksAvailable) {
    this.chunks = [];

    this.active = false;

    this.callback = onChunksAvailable;
  }

  start(stream) {
    if (this.active) {
      throw new Error("recorder is already running");
    }
    this.recorder = new MediaRecorder(stream, {
      mimeType: "audio/webm",
    });

    this.recorder.onstop = () => {
      stream.getAudioTracks()[0].stop();
      this.callback([...this.chunks]);

      setTimeout(() => {
        this.chunks = [];
      });

      this.active = false;
    };

    this.recorder.ondataavailable = (event) => this.chunks.push(event.data);

    this.active = true;
    this.recorder.start();
  }

  stop() {
    if (!this.active) {
      throw new Error("recorder is already stop");
    } else {
      this.recorder.stop();
    }
  }
}

let rec = new Recorder(async (chunks) => {
//using chunks then to get the stream
});

chrome.tabCapture.capture(
    {
      audio: true,
      video: false,
    },
    function (stream) {
        rec.start(stream);
}



from Original audio of tab gets muted while using chrome.tabCapture.capture() and MediaRecorder()

No comments:

Post a Comment