gpt4 book ai didi

javascript - WebRTC。不显示视频

转载 作者:行者123 更新时间:2023-11-30 11:45:27 25 4
gpt4 key购买 nike

我决定研究 WebRTC,但不显示视频。请帮助。我究竟做错了什么?使用 Chrome我的代码:

<html>

<head>
<meta charset="UTF-8">
</head>

<body>
<script>
window.onload = function () {
navigator.webkitGetUserMedia({ video: true }, getStream, noStream);
};

function getStream(stream) {
var url = window.webkitURL.createObjectURL(stream);
var video = document.getElementById('video');
video.src = url;
}

function noStream(faild) {

}
</script>
<video id="video" autoplay="autoplay" width="400"></video>
</body>

</html>

最佳答案

工作代码:

<head>
<meta charset="UTF-8"></script>
</head>

<body>
<script>
window.onload = function () {
var constraints = { audio: true, video: { width: 1280, height: 720 } };

navigator.mediaDevices.getUserMedia(constraints)
.then(function(mediaStream) {
var video = document.querySelector('video');
video.srcObject = mediaStream;
video.onloadedmetadata = function(e) {
video.play();
};
})
.catch(function(err) { console.log(err.name + ": " + err.message); });
};
</script>
<video id="video" autoplay="autoplay" width="400"></video>
</body>

</html>

关于javascript - WebRTC。不显示视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41127828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com