通过navigator.mediaDevices.getUserMedia获取到摄像头采集,然后在 video标签播放MDN 官方文档:https://developer.mozilla.org...<video id="video"></video>const constraints = { audio: true, video: { width: 1280, height: 720 } }; navigator.mediaDevices.getUserMedia(constraints) .then((mediaStream) => { const video = document.querySelector('video'); video.srcObject = mediaStream; video.onloadedmetadata = () => { video.play(); }; }) .catch((err) => { // always check for errors at the end. console.error(`${err.name}: ${err.message}`); });请自行复制到本地运行,在线编辑器一般都有权限问题,效果如下
通过
navigator.mediaDevices.getUserMedia
获取到摄像头采集,然后在video
标签播放MDN 官方文档:https://developer.mozilla.org...
请自行复制到本地运行,在线编辑器一般都有权限问题,效果如下