我真的有this https://stackoverflow.com/q/45692526/6048715问题,但 OP 的解决方案对我不起作用。
重申一下,我正在使用navigator.mediaDevices.getUserMedia()
在浏览器中捕获视频输入,并且在所有 Chrome 版本上一切正常,但相机在 IOS safari 上无法启动。没有错误,没有视频输入,什么都没有。
我最终创建了一个空的 html 项目,除了显示视频源之外什么也不做,以尝试看看我的其他代码是否可能干扰getUserMedia
代码,或者如果它是一个 Safari 问题并且它似乎是一个 Safari 问题。我部署了它here https://countdown-25aa0.firebaseapp.com/如果有人愿意请看一下,如果您有什么要补充的,请告诉我。
如果有人知道任何解决方法,请告诉我。
哦,这是该演示运行的代码:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1">
<title>getUserMedia to canvas</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<video playsinline autoplay></video>
<script src="./index.js" ></script>
</body>
</html>
// index.js
const video = document.querySelector('video');
(async () => {
try {
const devices = (await navigator.mediaDevices.enumerateDevices()).filter(v => v.kind === 'videoinput');
const deviceId = devices.findIndex(v => v.label.includes("Back"))?.deviceId || devices[0].deviceId;
const stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: { width: 720, deviceId } });
console.log(`stream: ${stream.id.substring(0, 4)}\nactive: ${stream.active}`);
alert(`stream: ${stream.id.substring(0, 4)}\nactive: ${stream.active}`);
video.srcObject = stream;
} catch (err) {
console.log(`err: ${err.name}: ${err.message}`);
alert(`err: ${err.name}: ${err.message}`);
}
})();
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)