use js to call the mobile camera, study the api of navigator.mediaDevices.getUserMedia, but successfully call up the camera on other mobile browsers, but QQ Browser cannot call it, and QQ Browser"s kernel version also supports the api, without any error message!
add another question:
after using constraints parameter modification,
facingMode: "environment"
is still proactive in actual use.
how sad!
I have tried to use compatible processing methods:
but still not feasible.
related codes
//
function getUserMedia(constrains,success,error){
if(navigator.mediaDevices.getUserMedia){
//API
navigator.mediaDevices.getUserMedia(constrains).then(success).catch(error);
} else if (navigator.webkitGetUserMedia){
//webkit
navigator.webkitGetUserMedia(constrains).then(success).catch(error);
} else if (navigator.mozGetUserMedia){
//Firefox
navagator.mozGetUserMedia(constrains).then(success).catch(error);
} else if (navigator.getUserMedia){
//API
navigator.getUserMedia(constrains).then(success).catch(error);
}
}
var video = document.getElementById("video");
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
//
function success(stream){
//webkit
var CompatibleURL = window.URL || window.webkitURL;
//video
video.src = CompatibleURL.createObjectURL(stream);
//
video.play();
}
//
function error(error){
console.log(":",error.name,error.message);
}
if (navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia){
//
const constraints = {
audio: true,
video: {
width: { ideal: 1280 },
height: { ideal: 720 },
frameRate: {
ideal: 10,
max: 15
},
facingMode: "environment"
}
};
getUserMedia(constraints,success,error);
} else {
alert("");
}
//
document.getElementById("capture").addEventListener("click",function(){
//
console.log("");
context.drawImage(video,0,0,480,320);
});