无闪存访问摄像头
问题描述:
我想创建一个使用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>
webcam.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);
})
})();
这不能做。 Se 的回答 - - http://*.com/questions/6976079/html-5-streaming-webcam-video/6976093#6976093 – aioobe 2012-03-10 07:10:24
不真实。在某些限制内,这是可能的。 – 2012-03-10 11:53:42
[在网页中访问网络摄像头]的可能重复(http://*.com/questions/9533773/accessing-webcam-in-web-pages) – 2017-04-11 12:25:40