最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError, captureStream is not a function - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Feb 5, 2018 at 13:40 Tomasz Mularczyk 36.2k19 gold badges118 silver badges174 bronze badges asked Feb 5, 2018 at 13:10 Abdul ManafAbdul Manaf 5,00310 gold badges56 silver badges98 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 16

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>

发布评论

评论列表(0)

  1. 暂无评论