【发布时间】:2021-06-30 09:29:36
【问题描述】:
我正在尝试将我的相机作为视频元素访问,但是当我运行程序时它不可见。
这是我的代码:
const myvideo=document.createElement('video');
myvideo.muted=true;
const videoGrid=document.getElementById("video_grid");
//I'm using a div element with id "video_grid" in my HTML file.This div does not contain any data (or child element) every property is set to default.
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then((stream)=>{
addVideoElement(myvideo,stream);
}).catch((e)=>console.log(e.name +":"+e.message ));
const addVideoElement=(video,stream)=>
{
video.srcObject=stream;
video.addEventListener('loadmetadata',()=>{
video.play();
});
videoGrid.append(video);
}
//HTML
<body>
<div id="video_grid">
</div>
<script src="script.js"></script>
</body>
视频流仅在我单击显示控件按钮后可见。你能帮我解决这个问题吗?
this is the camera view i get after clicking show controls and now i can play it manually
【问题讨论】:
-
对不起。现在可以理解了吗?
标签: javascript frontend webapi navigator