Firefox: drawImage(video) fails with NS_ERROR_NOT_AVAILABLE: Component is not available

安稳与你 提交于 2019-12-06 21:52:04

问题


Trying to call drawImage with a video whose source is a webcam feed seems to fail in Firefox with an NS_ERROR_NOT_AVAILABLE: Component is not available.

I have tried to wait for every event the video tag fires: play, playing, canplay, loadeddata, loadedmetadata, and so on, and nothing works. This seems to be because these events are firing before the stream is properly loaded into the <video> element.

JSFiddle with error (You can view the error in the console)

A side effect is that the width and height of the video is also incorrect.


回答1:


This is a bug in Firefox. The easiest fix is to simply keep trying until the error goes away, since no event fires at the correct time.

See: http://jsfiddle.net/9aT63/25/

Basically, you have to wrap the drawImage call in a try/catch block.

function drawVideo() {
  try {
    $vidCanvasCtx.drawImage($vid, 0, 0, $vidCanvas.width, $vidCanvas.height);
    ...
  } catch (e) {
    if (e.name == "NS_ERROR_NOT_AVAILABLE") {
      // Wait a bit before trying again; you may wish to change the
      // length of this delay.
      setTimeout(drawVideo, 100);
    } else {
      throw e;
    }
  }
}


来源:https://stackoverflow.com/questions/18580844/firefox-drawimagevideo-fails-with-ns-error-not-available-component-is-not-av

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!