Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError, captureStream is not a function

I have created a HTML5 page with video element. A sample video is played. After I had tried to record the stream in the video element. I am using the RecordRTC library for recording functionality. I have the following code

var stream = document.getElementById("my_video").captureStream();
var recorder = RecordRTC(stream, { 
  type: 'video'
});

recorder.startRecording();

The recording is successfully working on Chrome browser and Mozilla browser till version 57. But in last January , Mozilla browser updated to version 58. After this update, I got error when trying to record video using Mozilla.

The error message is:

TypeError 
message: document.getElementById("my_video").captureStream is not a function"

How to resolve this issue?

like image 645
Abdul Manaf Avatar asked Aug 30 '25 17:08

Abdul Manaf


1 Answers

Well, according to the docs this is experimental tech so Firefox requires you to prefix moz to the function name: mozCaptureStream. I'm a little surprised it worked at all previously.

You can check for the browser version with navigator.userAgent.

const sUsrAg = navigator.userAgent;

if (sUsrAg.indexOf('Firefox') > -1) {
  console.log('Firefox');
  document.getElementById("my_video").mozCaptureStream();
} else {
  console.log('Other');
  document.getElementById("my_video").captureStream();
}
<video id="my_video"></video>
like image 59
Andy Avatar answered Sep 02 '25 06:09

Andy