Vik*_*bas 2 javascript video webrtc
我决定学习 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>
Run Code Online (Sandbox Code Playgroud)
工作代码:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6743 次 |
| 最近记录: |