ImageCapture未定义

时间:2017-03-01 18:48:06

标签: javascript html getusermedia

我正在尝试执行此代码:



const canvas = document.querySelector('canvas');

var interval;
var track;

navigator.mediaDevices.getUserMedia({video: true})
.then(gotMedia)
.catch(err => console.error('getUserMedia() failed: ', err));

function gotMedia(mediastream) {
    track = mediastream.getVideoTracks()[0];
    var imageCapture = new ImageCapture(track);
    interval = setInterval(function () {
      imageCapture.grabFrame()
        .then(processFrame)
        .catch(err => console.error('grabFrame() failed: ', err));
    }, 1000);
}

function processFrame(imgData) {
    canvas.width = imgData.width;
    canvas.height = imgData.height;
    canvas.getContext('2d').drawImage(imgData, 0, 0);
}

function stopGrabFrame(e) {
    clearInterval(interval);
    track.stop();
}




从我的网络摄像头拍摄实时视频的快照,但它失败了,浏览器的控制台显示如下:

getUserMedia()失败:ReferenceError:未在gotMedia中定义ImageCapture

这是否意味着我的网络浏览器(谷歌浏览器)不支持ImageCapture?我能解决吗?

1 个答案:

答案 0 :(得分:2)

ImageCapture规范尚未在任何浏览器中实施,behind a flag除外。