用 node 打开,pc 可以正确执行,放在手机上会报错 NavigatorUserMediaError {name: "PermissionDeniedError", message: "", constraintName: ""}
//html
<video id="video" width="640" height="480"></video>
<button id="picture" type="button" name="button">拍摄</button>
<canvas id="canvas" width="640" height="480"></canvas>
// js
var video = document.getElementById("video");
var context = canvas.getContext("2d");
var button = document.getElementById("button")
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
navigator.getUserMedia({
video: true,
audio: true
},function(localMediaStream) {
video.src = window.URL.createObjectURL(localMediaStream);
video.play();
},function(err){
console.log(err)
})
button.addEventListener("click", function () {
context.drawImage(video, 0, 0, 640, 480);
});
手机端还没有多少支持的
