简体   繁体   English

Canvas.captureStream() 在 Angular 8 中不存在

[英]Canvas.captureStream() does not exist in Angular 8

I'm trying to send the content of an HTML canvas as a stream using webrtc.我正在尝试使用 webrtc 将 HTML 画布的内容作为流发送。

While in pure HTML + JS I can use Canvas.captureStream() to get an output stream, it seems like I can't find any way to do it using Angular 8. The code I'm using is:虽然在纯 HTML + JS 中我可以使用Canvas.captureStream()来获取输出流,但似乎我找不到任何使用 Angular 8 的方法。我使用的代码是:

  @ViewChild('canvas', {static: true})
  canvas: ElementRef<HTMLCanvasElement>;

  private canvasContext: CanvasRenderingContext2D;

  ngOnInit() {
    this.setupWebRtc();
    this.canvasContext = this.canvas.nativeElement.getContext('2d');
  }

  draw() {
    if (this.drawOnTop) {
      this.canvasContext.fillStyle = '#27bae7';
      this.canvasContext.fillRect(0, 100, this.canvas.nativeElement.width, 50);

      // Trying to get an output stream
      let  streamdata =  this.canvas.nativeElement.captureStream();
      console.log(streamdata);
   }

Using canvas.nativeElemet or canvasContext didn't seem to help as both have no captureStream() function.使用 canvas.nativeElemet 或 canvasContext 似乎没有帮助,因为两者都没有 captureStream() 函数。

I was thinking about using canvas.nativeElement.toDataURL();我正在考虑使用canvas.nativeElement.toDataURL(); but it seems like a bad approach.但这似乎是一个糟糕的方法。

I would love to get some suggestions.我很想得到一些建议。

Seems like the solution was a simple casting to <Any> .似乎解决方案是对<Any>的简单转换。 Meaning it was a typing issue.这意味着这是一个打字问题。 I used:我用了:

const  streamdata = (this.canvas.nativeElement as any).captureStream();

To get the stream.获取流。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测何时不支持`canvas.captureStream()`? - How to detect when `canvas.captureStream()` is not supported? 使用 canvas.captureStream() 使用 alpha 通道捕获视频 - Capture video with alpha channel using canvas.captureStream() 将“navigator.mediaDevices.getUserMedia”替换为“canvas.captureStream” - Replace "navigator.mediaDevices.getUserMedia" with "canvas.captureStream" Firefox canvas.captureStream 捕获处于非活动状态的黑帧 - Firefox canvas.captureStream captures black frames as was inactive 将drawImage与MediaRecorder一起使用时,为什么canvas.captureStream中的视频为空 - Why is video from canvas.captureStream empty when using drawImage with MediaRecorder <video>使用 MediaRecorder() 从<canvas>使用 canvas.captureStream() 在 firefox、chrome 上呈现不同 - <video> playback of recorded stream using MediaRecorder() from <canvas> using canvas.captureStream() renders differently at firefox, chromium 使用captureStream和mediaRecorder进行画布录制 - Canvas recording using captureStream and mediaRecorder Javascript:是否<audio> .captureStream() 在没有 play() 的情况下工作吗? - Javascript: Does <audio>.captureStream() work without play()? MediaRecorderAPI:如何使用来自 canvas 的 captureStream 和来自音频文件的音频源来生成媒体 Stream - MediaRecorderAPI : How to produce a Media Stream using captureStream from canvas & an audio source from an audio file 属性“ campanha”在类型“ DisputaComponent []”上不存在-Angular 2 - Property 'campanha' does not exist on type 'DisputaComponent[]' - Angular 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM