好,所以我有一个问题(不是问题,只需要一些指导)-我需要使用JavaScript访问客户端的实时流(iPhone摄像头)。
iPhone连接到的网站托管在我的PC上。
这应该发生:
192.168.1.XX
)getUserMedia
)这对我来说真的很难解决,任何帮助将不胜感激!
谢谢!
编辑 抱歉,您没有提前发布代码
<!DOCTYPE html>
<html>
<head>
<title>Accessing Web Camera in JS</title>
</head>
<body>
<video id="video"></video>
<canvas id="canvas"></canvas><br>
<button onclick="snap();">Snap</button>
<script type="text/javascript">
var video = document.getElementById('video');
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.oGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia;
if(navigator.getUserMedia){
navigator.getUserMedia({video:true}, streamWebCam, throwError);
}
function streamWebCam (stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
}
function throwError (e) {
alert(e.name);
}
function snap () {
canvas.width = video.clientWidth;
canvas.height = video.clientHeight;
context.drawImage(video, 0, 0);
}
</script>
</body>
</html>
顺便说一句: 我遵循了本教程的代码
Access Web Camera in JS | JavaScript Tutorials | Web Development Tutorials