大家好,我今天开始在项目中使用带有来自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'));
});
})();