Uncaught (in promise) TypeError: video.addEventListner is not a function
Uncaught (in promise) TypeError: video.addEventListner is not a function
我正在尝试访问我的笔记本电脑的音频和视频,并试图在屏幕上检索摄像头视频,在完成以下所有操作后,它只是访问我的摄像头和麦克风,但没有在屏幕上显示我的照片(只是黑屏)。在控制台显示此错误-
“script.js:16 Uncaught (in promise) TypeError: video.addEventListner 不是一个函数
在 addVideoStream (script.js:16)
在 script.js:11"
下面是我的脚本,html,css代码请帮忙-
const videoGrid=document.getElementById('video-grid');
const myVideo=document.createElement('video');
myVideo.muted=true;
let myVideoStream
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then(stream=>{
myVideoStream=stream;
addVideoStream(myVideo,stream);
})
const addVideoStream=(video,stream)=>{
video.srcObject=stream;
video.addEventListner('loadedmetadata',()=>{
video.play();
})
videoGrid.append(video);
}
#video-grid{
display:flex;
justify-content:center;
}
video{
height:300px;
width:400px;
}
<!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, initial-scale=1.0">
<title>Zoom RJ</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="video-grid">
</div>
<script src="script.js"></script>
</body>
</html>
您的语法有错别字。
试试这个。
video.addEventListener
.
Listener
缺少 e
我正在尝试访问我的笔记本电脑的音频和视频,并试图在屏幕上检索摄像头视频,在完成以下所有操作后,它只是访问我的摄像头和麦克风,但没有在屏幕上显示我的照片(只是黑屏)。在控制台显示此错误- “script.js:16 Uncaught (in promise) TypeError: video.addEventListner 不是一个函数 在 addVideoStream (script.js:16) 在 script.js:11"
下面是我的脚本,html,css代码请帮忙-
const videoGrid=document.getElementById('video-grid');
const myVideo=document.createElement('video');
myVideo.muted=true;
let myVideoStream
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then(stream=>{
myVideoStream=stream;
addVideoStream(myVideo,stream);
})
const addVideoStream=(video,stream)=>{
video.srcObject=stream;
video.addEventListner('loadedmetadata',()=>{
video.play();
})
videoGrid.append(video);
}
#video-grid{
display:flex;
justify-content:center;
}
video{
height:300px;
width:400px;
}
<!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, initial-scale=1.0">
<title>Zoom RJ</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="video-grid">
</div>
<script src="script.js"></script>
</body>
</html>
您的语法有错别字。 试试这个。
video.addEventListener
.
Listener
e