下面是我的代码,可以在带有前置摄像头的 android 和 ios 11 中正常工作,而当我使用后置摄像头时会出错
以下作品
video: { width: 400, height: 200, facingMode: "user" }
以下无效
video: { width: 400, height: 200, facingMode: "environment" }
完整代码
**
var constraints = window.constraints = {
audio: false,
video: { width: 400, height: 200, facingMode: "environment" }
};
function handleSuccess(stream) {
var videoTracks = stream.getVideoTracks();
console.log('Got stream with constraints:', constraints);
console.log('Using video device: ' + videoTracks[0].label);
stream.oninactive = function() {
console.log('Stream inactive');
};
window.stream = stream; // make variable available to browser console
video.srcObject = stream;
}
function handleError(error) {
if (error.name === 'ConstraintNotSatisfiedError') {
errorMsg('The resolution ' + constraints.video.width.exact + 'x' +
constraints.video.width.exact + ' px is not supported by your device.');
} else if (error.name === 'ermissionDeniedError') {
errorMsg('ermissions have not been granted to use your camera and ' +
'microphone, you need to allow the page access to your devices in ' +
'order for the demo to work.');
}
errorMsg('getUserMedia error: ' + error.name, error);
}
function errorMsg(msg, error) {
errorElement.innerHTML += '<p>' + msg + '</p>';
if (typeof error !== 'undefined') {
console.error(error);
}
}
navigator.mediaDevices.getUserMedia(constraints).
then(handleSuccess).catch(handleError);
**
Best Answer-推荐答案 strong>
目前苹果iOS11下的getUserMedia 不支持width 和height 约束。
使用后置摄像头的唯一方法是通过以下约束:
var constraints = window.constraints = {
audio: false,
video: { facingMode: 'environment' }
};
我为此在 Apple 中打开了一个错误,但它已作为副本关闭。
请密切关注 Apple 关于此问题的更新。
关于javascript - Webrtc后置摄像头在IOS 11中不起作用,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/49206667/
|