gpt4 book ai didi

javascript - Webrtc 后置摄像头在 IOS 11 中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:53:22 24 4
gpt4 key购买 nike

下面是我的代码,在带有前置摄像头的 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 === 'PermissionDeniedError') {
errorMsg('Permissions 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);

**

最佳答案

目前苹果iOS11下getUserMedia不支持widthheight约束

使用后置摄像头的唯一方法是通过以下限制:

var constraints = window.constraints = {
audio: false,
video: { facingMode: 'environment' }
};

为此,我在 Apple 中打开了一个错误,但它被关闭了。密切关注 Apple 关于此问题的更新。

关于javascript - Webrtc 后置摄像头在 IOS 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49206667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com