打开WebCam

hello,因为之前的pro需要打开webcam,这里贴一下在vuejs里面打开摄像头的代码:

async setupWebcam(){

this.webcamElement=document.getElementById("webcam");

return new Promise((resolve,reject)=>{

const navigatorAny=navigator;

navigator.getUserMedia=navigator.getUserMedia ||navigatorAny.webkitGetUserMedia

||navigatorAny.mozGetUserMedia||navigatorAny.msGetUserMedia;

if(navigator.getUserMedia){

navigator.getUserMedia({video:true},stream => {

this.webcamElement.srcObject=stream;

this.webcamElement.addEventListener("loadeddata",()=>resolve(),false);

},error => reject());

}else {

reject();

}

});

}

最近忙得有点冒烟....

你可能感兴趣的:(打开WebCam)