码迷,mamicode.com
首页 > 移动开发 > 详细

HTML5调用手机摄像头,仅仅支持OPPOHD浏览器

时间:2014-06-13 07:31:31      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

bubuko.com,布布扣
 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4   <meta charset="UTF-8">
 5   <title>HTML5调用手机摄像头,仅仅支持OPPOHD浏览器</title> 
 6 <style>  
 7 #video { border: 1px solid #ccc; display:inline-block; }  
 8 #canvas { border: 1px solid #ccc; display:inline-block;}  
 9 #take_photo{background-color:orange;width:100px;height:30px;border:0px;}  
10 </style>  
11 </head>  
12 <body>  
13 <video id="video" width="480" height="320" autoplay></video>  
14 <canvas id="canvas" width="480" height="320"></canvas>  
15 <input id="take_photo" name="take_photo" value="拍照" type="button" />  
16 </body>  
17 </html>  
18   
19 <script type="text/javascript">
20     window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
21     window.addEventListener("DOMContentLoaded", function () {
22         var canvas = document.getElementById("canvas"), //画布容器  
23     context = canvas.getContext("2d"), //创建绘画对象  
24     video = document.getElementById("video"), //视频容器  
25     videoobj = { "video": true },
26     errback = function (error) {
27         console.log("error", error.code);
28     };
29         if (navigator.getUserMedia) {
30             navigator.getUserMedia(videoobj, function (stream) {
31                 video.src = stream;
32             }, errback);
33         } else if (navigator.webkitGetUserMedia) {//chrome  
34             navigator.webkitGetUserMedia(videoobj, function (stream) {
35                 video.src = window.URL.createObjectURL(stream) || stream;
36             }, errback)
37         }
38         else if (navigator.mozGetUserMedia) {//firefox  
39             navigator.mozGetUserMedia(videoobj, function (stream) {
40                 video.src = window.URL.createObjectURL(stream) || stream;
41             }, errback)
42         }
43         else if (navigator.msGetUserMedia) {//IE  
44             navigator.msGetUserMedia(videoobj, function (stream) {
45                 video.src = window.URL.createObjectURL(stream) || stream;
46             }, errback)
47         }
48         video.play();
49         document.getElementById("take_photo").addEventListener("click", function () {
50             context.drawImage(video, 0, 0, 480, 320); //视频截屏  
51         });
52     }, false);  
53 </script>  
bubuko.com,布布扣

 

HTML5调用手机摄像头,仅仅支持OPPOHD浏览器,布布扣,bubuko.com

HTML5调用手机摄像头,仅仅支持OPPOHD浏览器

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/liubeimeng/p/3781188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!