-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgetusermedia.html
160 lines (140 loc) · 5.34 KB
/
getusermedia.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="title" content="getMediaUser API">
<meta name="description" content="API for media devices.">
<meta name="image" content="">
<meta name="site" content="">
<link type="text/css" rel="stylesheet" href="./css/fonts.css" />
<link type="text/css" rel="stylesheet" href="./css/style.css" />
<title>Web APIs getUserMedia Example</title>
<style>
.justDiv {
position: relative;
}
#canvas {
width: 100%;
margin: 2px 0px;
height: inherit;
}
.video {
position: relative;
}
.canvasDiv {
position: absolute;
z-index: 100;
top: 0;
left: 0;
width: 100%;
border: 1px solid green;
border-radius: 3px;
background: white;
height: 100%;
}
.close-btn {
border-radius: 125%;
position: absolute;
z-index: 1000;
top: 15px;
left: 90%;
text-align: center;
cursor: pointer;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.33);
}
</style>
<body>
<header>
<div class="header-bars" onclick="toggleNav('.aside-navbar')"><span class="header-bar fa-bars"></span></div>
<div class="title-bar"><h2>Web APIs</h2></div>
<div class="navbar">
<ul class="navbar-nav">
<li class="navbar-nav-item">
<a onclick="toggle('.dropdown')">More APIs</a>
<ul class="dropdown close">
<li class="dropdown-item"><a>History API</a></li>
<li class="dropdown-item"><a>Vibration API</a></li>
<li class="dropdown-item"><a>Fullscreen API</a></li>
<li class="dropdown-item"><a href="./index.html">More ...</a></li>
</ul>
</li>
</ul>
</div>
</header>
<aside class="aside-sidebar" id="leftAside">
<div class="aside-sidebar-header">
<h3>Web APIs Menu</h3></div>
<ul>
<li><a class="aside-sidebar-active" href="./getusermedia.html">getUserMedia API</a></li>
<li><a href="./bluetooth.html">Bluetooth API</a></li>
<li><a href="./touch.html">Touch API</a></li>
<li><a href="./battery.html">Battery API</a></li>
<li><a href="./clipboard.html">Clipboard API</a></li>
<li><a href="./audio.html">Web Audio API</a></li>
<li><a href="./broadcastchannel.html">Broadcastchannel Messaging API</a></li>
<li><a href="./channelmessaging.html">Channel Messaging API</a></li>
<li><a href="./fullscreen.html">Fullscreen API</a></li>
<li><a href="./history.html">History API</a></li>
<li><a href="./vibration.html">Vibration API</a></li>
<li><a href="./url.html">URL API</a></li>
<li><a href="./speech.html">Web Speech API</a></li>
<li><a href="./resizeobserver.html">Resize Observer API</a></li>
<li><a href="./touch.html">Touch API</a></li>
<li><a href="./pointerlock.html">Pointer Lock API</a></li>
<li><a href="./paymentrequest.html">Payment Request API</a></li>
<li><a href="./pagevisibility.html">Page Visibility API</a></li>
</ul>
</aside>
<div class="container">
<div class="web-api-cnt">
<div class="web-api-card">
<div class="web-api-card-head">
Demo - getUserMedia
</div>
<div class="web-api-card-body">
<div class="info">
<h4>Info</h4>
<p>This uses the <b>getUserMedia</b> to get your web camera to stream live feed to a <b>video</b> element.</p>
<p>The <b>Capture</b> button will take a snapshot of the <b>video</b> element feed and draw it on a <b>canvas</b> element.</p>
</div>
<div class="justDiv">
<div>
<video id="video"></video>
</div>
<div>
<button onclick="capture()">Capture</button>
</div>
<div class="close" id="canvasCnt">
<canvas id="canvas"></canvas>
<div>
<button class="close-btn" onclick="closeDiv()">X</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="./js/script.js"></script>
<script>
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then((stream) => {
video.srcObject = stream
video.play()
})
function capture() {
const context = canvas.getContext("2d")
context.drawImage(video, 0, 0, canvas.width, canvas.height)
video.pause()
canvasCnt.classList.add("canvasDiv")
canvasCnt.classList.remove("close")
}
function closeDiv() {
canvasCnt.classList.remove("canvasDiv")
canvasCnt.classList.add("close")
video.play()
}
</script>
</html>