js 打开摄像头方法 (定制摄像头)

var video = document.getElementById("video");
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
    navigator.mediaDevices.getUserMedia({
        video: true,
        audio: true
    }).then(function(stream) {
        console.log(stream);
        mediaStreamTrack = typeof stream.stop === 'function' ? stream : stream.getTracks()[1];
    video.src = (window.URL || window.webkitURL).createObjectURL(stream);
        video.play();
    }).catch(function(err) {
        console.log(err);
})
}

  

 

第二种

//媒体对象
	    window.navigator.getMedia = window.navigator.getUserMedia ||
	                         window.navigator.webkitGetUserMedia ||
	                         window.navigator.mozGetUserMedia ||
	                         window.navigator.msGetUserMedia;
	    window.navigator.getMedia({
	        video: true, //使用摄像头对象
	        audio: false  //不适用音频
	    }, function(strem){
	        console.log(strem);
	        video.src = vendorUrl.createObjectURL(strem);
	        video.play();
		     
	    }, function(error) {
	        console.log(error);
	    });

  

转载自:https://www.cnblogs.com/imwtr/p/6413595.html

posted @ 2018-03-16 14:22  飞尽堂前燕  阅读(1296)  评论(0编辑  收藏  举报