<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<body>
<video id="video" width="480" height="320" controls>
</video>
<div>
<button id="capture"></button>
</div>
<canvas id="canvas" width="480" height="320"></canvas>
<script>
//
function getUserMedia(constraints, success, error) {
if (navigator.mediaDevices.getUserMedia) {
//API
navigator.mediaDevices.getUserMedia(constraints).then(success).catch(error);
} else if (navigator.webkitGetUserMedia) {
//webkit
navigator.webkitGetUserMedia(constraints,success, error)
} else if (navigator.mozGetUserMedia) {
//firfox
navigator.mozGetUserMedia(constraints, success, error);
} else if (navigator.getUserMedia) {
//API
navigator.getUserMedia(constraints, success, error);
}
}
let video = document.getElementById("video");
let canvas = document.getElementById("canvas");
let context = canvas.getContext("2d");
function success(stream) {
//webkit
let CompatibleURL = window.URL || window.webkitURL;
//video
console.log(stream);
//video.src = CompatibleURL.createObjectURL(stream);
video.srcObject = stream;
video.play();
}
function error(error) {
console.log(`${error.name}, ${error.message}`);
}
if (navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia) {
//,
getUserMedia({video : {width: 480, height: 320}}, success, error);
} else {
alert("");
}
document.getElementById("capture").addEventListener("click", function () {
context.drawImage(video, 0, 0, 480, 320);
})
</script>
</body>
</html>
when I open the file://
prompt
directly when I save as html, it is OK to allow (the chrome under PC has a hint, the prompt box does not appear under safari, and neither safari, Wechat nor chrome pops up on the mobile phone), what can I do?