【发布时间】:2014-04-29 05:12:40
【问题描述】:
我想在我的网络应用程序中实时显示来自我的网络摄像头的数据。这是我的代码。使用此代码,我可以看到来自网络摄像头的实时数据。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="stuff, to, help, search, engines, not" name="keywords">
<meta content="What this page is about." name="description">
<meta content="Display Webcam Stream" name="title">
<title>Display Webcam Stream</title>
<style>
#container {
margin: 0px auto;
width: 500px;
height: 375px;
border: 10px #333 solid;
}
#videoElement {
width: 500px;
height: 375px;
background-color: #666;
}
</style>
</head>
<body>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
}
function videoError(e) {
alert("error");
}
</script>
</body>
</html>
假设我有一个有 4 个页面的 web 应用程序。我想在我的第三页的一个 div 中显示此网络摄像头数据。我该怎么做。我需要更改其中的任何内容吗?
video.src = window.URL.createObjectURL(stream);
【问题讨论】:
-
您的意思是,在一个独特的页面上,您只想做同样的事情?将您的 JS 移动到该页面并确保它抓取正确的 html 元素。
-
我只在同一个页面写js。
标签: javascript html webcam webrtc getusermedia