首页  >  文章  >  web前端  >  HTML5调用摄像头的示例代码分享

HTML5调用摄像头的示例代码分享

黄舟
黄舟原创
2017-03-20 15:39:212843浏览

下面小编就为大家带来一篇h5调用摄像头的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>GetUserMedia实例</title>
</head>
<body>
<video id="video" autoplay><ideo>
</body>
<script type="text/javascript">
var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);   
getUserMedia.call(navigator, {   
video: true,   
audio: true   
}, function(localMediaStream) {   
var video = document.getElementById(&#39;video&#39;);   
video.src = window.URL.createObjectURL(localMediaStream);   
video.onloadedmetadata = function(e) {   
console.log("Label: " + localMediaStream.label);   
console.log("AudioTracks" , localMediaStream.getAudioTracks());   
console.log("VideoTracks" , localMediaStream.getVideoTracks());   
};   
}, function(e) {   
console.log(&#39;Reeeejected!&#39;, e);   
});   
</script>
<html>

以上是HTML5调用摄像头的示例代码分享的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn