在Angular / Electron应用程序中使用MediaRecorder对象

问题描述

我正在尝试使用MediaRecorder对象,但是编译器无法识别它。

startStreaming(){
 const mediaStream=this.canvas.captureStream(30);
 this.mediaRecorder = new MediaRecorder(mediaStream,{
  mimeType: 'video/webm;codecs=h264',videoBitsPerSecond : 3 * 1024 * 1024
 });
 this.mediaRecorder.start(1000);
}

this.canvas被声明为HTMLCanvasElement,但我在captureStream上仍然遇到此错误Property 'captureStream' does not exist on type 'HTMLCanvasElement'.

在下一行,我有Cannot find name 'MediaRecorder'.

到目前为止,我一直尝试:

  1. 安装dom-mediacapture-record:npm install -d @types/dom-mediacapture-record
  2. 将“ dom-mediacapture-record”添加types中的tsconfig.json

但是似乎没有任何效果。有什么想法吗?

解决方法

您是否尝试将“dom-mediacapture-record”添加到 types 中的 tsconfig.app.json 数组而不是 tsconfig.json
这对我有用。