html5 调用摄像头
- <html>
- <body>
- <video id="video" autoplay=""style='width:640px;height:480px'></video>
- <canvas id="canvas" width="640" height="480"></canvas>
- <script>
- var video=document.getElementById("video");
- var context=canvas.getContext("2d");
- var errocb=function(){
- console.log("wrong");
- }
- if (navigator.getUserMedia) { // 标准的API
- navigator.getUserMedia({ "video": true }, function (stream) {
- video.src = stream;
- video.play();
- }, errocb);
- } else if (navigator.webkitGetUserMedia) { // WebKit 核心的API
- navigator.webkitGetUserMedia({ "video": true }, function (stream) {
- video.src = window.webkitURL.createObjectURL(stream);
- video.play();
- }, errocb);
- }
- </script>
- </body>
- </html>
来源: https://www.oschina.net/code/snippet_105637_58517