我想使用 HTML 5 元素和 JavaScript 创建一个视频聊天应用程序,我不想使用 Flash 访问用户的网络摄像头。
我怎样才能仅使用 HTML 和 JavaScript 来完成此任务?
最佳答案
在撰写本文时,最好的解决方案是 WebRTC。是supported in Chrome, Mozilla and Opera , 但在 Internet Explorer 和 Safari 中仍然不可用。
简约演示。
Index.html
<!DOCTYPE html>
<head>
</head>
<body>
<video></video>
<script src="webcam.js"></script>
</body>
网络摄像头.js
(function () {
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia);
navigator.getMedia(
// constraints
{video:true, audio:false},
// success callback
function (mediaStream) {
var video = document.getElementsByTagName('video')[0];
video.src = window.URL.createObjectURL(mediaStream);
video.play();
},
//handle error
function (error) {
console.log(error);
})
})();
关于javascript - 在没有 Flash 的情况下访问网络摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9644612/