-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcameraAPI.html
More file actions
58 lines (50 loc) · 1.93 KB
/
cameraAPI.html
File metadata and controls
58 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- basic.html -->
<title>cameraAPI</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1> The Camera API </h1>
<p>
This paragraph is about the getUserMedia()-API, which is about to replace the deprecated camera-API.<br>
The method <br>
<code>
navigator.mediaDevices.getUserMedia()
</code>
<br>
asks for the users permission to access an input device like the camera. <br>
If accepted, it returns a <i>Promise</i> which resolves into a <i>MediaStream</i>. The <i>MediaStream</i> can contain a video track, an audio track and various other tracks.<br>
This stream can than be set as the <i>srcObject</i> of an video element in the HTML-Appliaction which the live stream of the selected input device. <br>
Use it like this: <br>
<code>
var video = document.getElementById('video'); <br>
<br>
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { <br>
navigator.mediaDevices.getUserMedia({ <br>
video: true <br>
}).then(function (stream) { <br>
//video.src = window.URL.createObjectURL(stream); <br>
video.srcObject = stream; <br>
video.play(); <br>
}); <br>
} <br>
</code>
Try it out below! <br>
</p>
<video id="video" width="640" height="480" autoplay></video>
<script>
var video = document.getElementById('video');
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
video: true
}).then(function (stream) {
video.srcObject = stream;
video.play();
});
}
</script>
<a href="index.html"> back </a>
</body>