eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.43k stars 1.44k forks source link

video demos on the website can't run #375

Open fantasticit opened 4 years ago

fantasticit commented 4 years ago

First, thanks for the awesome lib!

In my device, any demo on the website which use video tag can't run correctly.

device info: macOs/10.14.6 Chrome/76.0.3809.87

And, I found some info in MDN. According to it, I rewrite tracking.initUserMedia_.

tracking.initUserMedia_ = function(element, opt_options) {
  // window.navigator.getUserMedia(
  //   {
  //     video: true,
  //     audio: !!(opt_options && opt_options.audio)
  //   },
  //   function(stream) {
  //     try {
  //       element.src = window.URL.createObjectURL(stream);
  //     } catch (err) {
  //       element.src = stream;
  //     }
  //   },
  //   function() {
  //     throw Error("Cannot capture user camera.");
  //   }
  // );

  window.navigator.mediaDevices
    .getUserMedia({
      video: true,
      audio: !!(opt_options && opt_options.audio)
    })
    .then(stream => {
      element.srcObject = stream;
      video.onloadedmetadata = function(e) {
        element.play();
      };
    })
    .catch(err => {
      throw Error("Cannot capture user camera.", err);
    });
};

Then, the demos works!

qsenn35 commented 4 years ago

Running into same issue, seems like bower is changing element.srcObject to element.src. Digging to find a fix for this.