如何解决为什么网络摄像头在 Iphone 的 chrome 中不起作用?
webcam capture not work in iphone browser
webcam also work in android chrome
我正在尝试在我的网站上进行捕获。但它在安卓和桌面上运行良好。但是为什么它在 chrome 或 safari 的 Iphone 中不起作用。当有“点击打开相机”字样时,相机无法在网络中打开?有什么建议吗?
var videoSelect = document.querySelector('select#videoSource');
navigator.mediaDevices.enumerateDevices().then(gotDevices);
videoSelect.onchange = ganti;
function gotDevices(deviceInfos) {
for (var i = 0; i !== deviceInfos.length; ++i) {
var deviceInfo = deviceInfos[i];
var option = document.createElement('option');
option.value = deviceInfo.deviceId;
if (deviceInfo.kind === 'videoinput') {
option.text = deviceInfo.label || 'camera ' +
(videoSelect.length + 1);
videoSelect.appendChild(option);
} else {
console.log('Found one other kind of source/device: ',deviceInfo);
}
}
}
function startWebcam() {
var constraints = {
deviceId: {
exact: videoSelect.value
}
};
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},any: function() {
return (isMobile.Android() || isMobile.BlackBerry() ||
isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
console.log(window.matchMedia("(orientation: portrait)").matches);
console.log(isMobile.Android);
console.log(isMobile);
if (isMobile.Android && window.matchMedia("(orientation: portrait)").matches) {
$("#devicetype").val("mobile");
Webcam.set({
width : 240,height : 320,dest_width : 480,dest_height : 640,image_format : 'jpeg',jpeg_quality : 100,constraints : constraints
});
try {
$('#my_cameraSelfie_mobile').addClass('frameAddStyle'); //frameAddStyleselfie
Webcam.attach('#my_cameraSelfie_mobile');
var content = '';
content += '<img src="https://abc.png" class="img-responsive" style="opacity: 0.5;margin-top: 0 ;margin-left: 50%; transform: translate(-50%,-50%); z-index: 1000; " >';
jQuery('#my_cameraSelfie_mobileMasking').append(content);
document.getElementById('btnStart').style.display = "none";
document.getElementById('btnStop').style.display = "none";
if($("#firstsnapshot").val()!=1){//not use
setTimeout(function(){
take_snapshot();
},700); //notuse
}else{
setTimeout(function(){
document.getElementById('btnSnap').style.display = "";
},2000);
}
document.getElementById('btnCancel').style.display = "none";
} catch (exp) {
console.error(exp);
$Error("Webcam access error! Try to use https:// protocol");
}
} else {
$("#devicetype").val("desktop");
Webcam.set({
width: 640,height: 480,image_format: 'jpeg',jpeg_quality: 100,constraints: constraints
});
try {
Webcam.attach('#my_camera');
var img = document.createElement("img");
img.src = "https://abc.png";
var src = document.getElementById("my_camera_test");
src.appendChild(img);
document.getElementById('btnStart').style.display = "none";
document.getElementById('btnStop').style.display = "none";
if($("#firstsnapshot").val()!=1){//not use
setTimeout(function(){
take_snapshot();
},700);//not use
}else{
setTimeout(function(){
document.getElementById('btnSnap').style.display = "";
},2000);
}
document.getElementById('btnCancel').style.display = "none";
} catch (exp) {
console.error(exp);
$Error("Webcam access error! Try to use https:// protocol");
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。