TypeError,captureStream不是函数

时间:2018-02-05 13:10:40

标签: javascript html5 html5-video video-recording recordrtc

我创建了一个带有视频元素的HTML5页面。播放示例视频。我尝试在视频元素中录制流后。我正在使用RecordRTC库来记录功能。我有以下代码

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

recorder.startRecording();

录制在Chrome浏览器和Mozilla浏览器上成功运行至版本57.但是在去年1月,Mozilla浏览器更新到版本58.在此更新后,我在尝试使用Mozilla录制视频时出错。

错误消息是:

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

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

好吧,according to the docs this is experimental tech因此Firefox要求您在moz前加上函数名称:mozCaptureStream。我之前对它的工作有点惊讶。

您可以使用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>