Home  >  Article  >  Web Front-end  >  HTML5 sample code sharing for calling camera

HTML5 sample code sharing for calling camera

黄舟
黄舟Original
2017-03-20 15:39:212847browse

The following editor will bring you an implementation method of calling the camera in h5. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look

<!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>

The above is the detailed content of HTML5 sample code sharing for calling camera. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn