0

大家好,我今天开始在项目中使用带有来自https://browsersync.io/#install的简单配置的 browsersync来使用网络摄像头捕获图片。它工作得很好,但突然停止工作,现在它没有向我显示来自相机的图像,并且在 chrome 中现在出现错误video.play is not a function即使使用 gulp 文件来启动本地服务器,所以不要不知道发生了什么。以前有人遇到过这样的问题吗?

这是我的 js 文件:

(function(){
var video = document.getElementById('video'),
    canvas = document.getElementById('canvas'),
    context = canvas.getContext('2d'),
    photo = document.getElementById('photo'),
    vendorUrl = window.URL || window.webkitURL;

navigator.getMedia = navigator.getUserMedia||
                     navigator.webkitGetUserMedia ||
                     navigator.mozGetUserMedia ||
                     navigator.msGetUserMedia;

navigator.getMedia({
    video: true,
    audio: false
}, function(stream) {
    video.src = vendorUrl.createObjectURL(stream);
    video.play();
}, function(error){
    //An error occured
    //error.code
});

document.getElementById('snap').addEventListener('click', function(){
    context.drawImage(video, 0, 0, 400, 300);
    photo.setAttribute('src', canvas.toDataURL('image/png'));
});

})();

4

1 回答 1

0

我对完全相同的源代码有同样的问题。我将相机图像解决方案迁移到 yii2,我的问题是 #video 是 div 元素而不是 video 元素,如果将其更改为 video 标签,它将完美运行。

:)

于 2016-08-25T10:29:10.293 回答