Home > Software design >  Usage of mozCaptureStream stop audio output of video element
Usage of mozCaptureStream stop audio output of video element

Time:05-27

Call mozCaptureStream API on video tag causes to stop audio output

OS: Windows 10 (x64) Browser: Mozilla Firefox 100.0.2 (64-bit)

CodePudding user response:

This is BUG 1178751, Firefox does destroy the AudioSink from the original media element so that it's instead transferred into the newly produced MediaStream.

They're still working on it (after 7 years), and hopefully they'll fix it one day and stop prefixing captureStream().

Until this day comes, you can use an AudioContext to play the MediaStream's audio:

const vid = document.querySelector("video");
vid.onplay = (evt) => {
  const stream = vid.captureStream ? vid.captureStream() : vid.mozCaptureStreamUntilEnded();
  console.log(stream);
  if (!vid.captureStream) {
    const ctx = new AudioContext();
    const dest = ctx.createMediaStreamSource(stream);
    dest.connect(ctx.destination);
  }
};
<video src="https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm" crossorigin controls autoplay></video>

  • Related