求助,wap2app打包的APP,里面调用了个js打开摄像头的功能,在浏览器里正常调出,打包了怎么就调不出来了
在浏览器里打开有允许调用的提示,打包了就没有提示了,是不是打包的浏览器屏蔽了提示?
调用代码:
<!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>video</title>
<script type="text/javascript">
window.onload = function(){
const video = document.getElementById("video"),
oBtn = document.getElementById("btn"),
canvas = document.getElementById("canvas"),
context = canvas.getContext("2d");
var flag = getUserMedia({video:{height:330,width:400}}, success, error);
oBtn.addEventListener("click", function(){
if(flag === true){ //getUserMedia返回false说明调用失败
context.drawImage(video, 0, 0, 400, 330);
}else{
console.log("获取摄像头失败,无法拍照!");
}
},false);
function getUserMedia(constraints, success, error){
if(navigator.mediaDevices.getUserMedia){ //最新版API
navigator.mediaDevices.getUserMedia(constraints).then(success).catch(error);
}else if(navigator.getUserMedia){ //旧版API
navigator.getUserMedia(constraints, success, error);
}else if(navigator.mozGetUserMedia){ //Firefox API
navigator.mozGetUserMedia(constraints, success, error);
}else if(navigator.webkitGetUserMedia){ //webkit内核浏览器 API
navigator.webkitGetUserMedia(constraints, success, error);
}else{
return false;
}
return true;
}
function success(stream){
video.srcObject = stream;
video.play();
}
function error(err){
console.log(err.message,err.name);
}
}
</script>
</head>
<body>
<video id="video" height="330" width="400" controls></video>
<button id="btn">拍照</button>
<canvas id="canvas" height="330" width="400"></canvas>
</body>
</html>
二福
解决了吗?
2019-10-21 10:02