javascript - Webrtc后置摄像头在IOS 11中不起作用
<p><p>下面是我的代码,可以在带有前置摄像头的 android 和 ios 11 中正常工作,而当我使用后置摄像头时会出错</p>
<p><strong>以下作品</strong></p>
<pre><code>video: { width: 400, height: 200, facingMode: "user"}
</code></pre>
<p><strong>以下无效</strong></p>
<pre><code>video: { width: 400, height: 200, facingMode: "environment"}
</code></pre>
<p><strong>完整代码</strong></p>
<p>**</p>
<pre><code>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.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);
</code></pre>
<p>**</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>目前苹果iOS11下的<code>getUserMedia</code><strong>不支持<code>width</code>和<code>height</code>约束。</strong> </p >
<p>使用后置摄像头的唯一方法是通过以下约束:</p>
<pre><code>var constraints = window.constraints = {
audio: false,
video: { facingMode: 'environment' }
};
</code></pre>
<p>我为此在 Apple 中打开了一个错误,但它已作为副本关闭。
请密切关注 Apple 关于此问题的更新。</p></p>
<p style="font-size: 20px;">关于javascript - Webrtc后置摄像头在IOS 11中不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/49206667/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/49206667/
</a>
</p>
页:
[1]