1if (navigator.mediaDevices.getUserMedia) {
2 navigator.mediaDevices.getUserMedia({ video: true })
3 .then(function (stream) {
4 video.srcObject = stream;
5 })
6 .catch(function (err0r) {
7 console.log("Something went wrong!");
8 });
9}
1<!DOCTYPE html>
2<html>
3<head>
4<meta charset="utf-8">
5<title>Display Webcam Stream</title>
6
7<style>
8#container {
9 margin: 0px auto;
10 width: 500px;
11 height: 375px;
12 border: 10px #333 solid;
13}
14#videoElement {
15 width: 500px;
16 height: 375px;
17 background-color: #666;
18}
19</style>
20</head>
21
22<body>
23<div id="container">
24 <video autoplay="true" id="videoElement">
25
26 </video>
27</div>
28<script>
29
30</script>
31</body>
32</html>
1if (navigator.mediaDevices.getUserMedia) {
2 navigator.mediaDevices.getUserMedia({ video: true })
3 .then(function (stream) {
4 video.srcObject = stream;
5 })
6 .catch(function (err0r) {
7 console.log("Something went wrong!");
8 });
9}
1function stop(e) {
2 var stream = video.srcObject;
3 var tracks = stream.getTracks();
4
5 for (var i = 0; i < tracks.length; i++) {
6 var track = tracks[i];
7 track.stop();
8 }
9
10 video.srcObject = null;
11}
1var video = document.querySelector("#videoElement");
2
3if (navigator.mediaDevices.getUserMedia) {
4 navigator.mediaDevices.getUserMedia({ video: true })
5 .then(function (stream) {
6 video.srcObject = stream;
7 })
8 .catch(function (err0r) {
9 console.log("Something went wrong!");
10 });
11}
1if (navigator.mediaDevices.getUserMedia) {
2 navigator.mediaDevices.getUserMedia({ video: true })
3 .then(function (stream) {
4 video.srcObject = stream;
5 })
6 .catch(function (err0r) {
7 console.log("Something went wrong!");
8 });
9}