-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
58 lines (46 loc) · 1.45 KB
/
index.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
<div id="container">
<p>Click a button to call <code>getUserMedia()</code> with appropriate resolution.</p>
<br>
<div id="buttons">
<button onclick="getMedia(qvgaConstraints)">QVGA</button>
<button onclick="getMedia(vgaConstraints)">VGA (gUM)</button>
<button onclick="constraintChange()">VGA (applyConstraints)</button>
</div>
<video id="video" playsinline autoplay></video>
</div>
<script>
let stream;
let currentWidth = 0;
let currentHeight = 0;
const qvgaConstraints = {
video: {width: {exact: 320}, height: {exact: 240}}
};
const vgaConstraints = {
video: {width: {exact: 640}, height: {exact: 480}}
};
function gotStream(mediaStream) {
stream = window.stream = mediaStream; // stream available to console
video.srcObject = mediaStream;
const track = mediaStream.getVideoTracks()[0];
const constraints = track.getConstraints();
console.log('Result constraints: ' + JSON.stringify(constraints));
}
function constraintChange() {
const track = window.stream.getVideoTracks()[0];
const constraints = vgaConstraints.video;
console.log('applying ' + JSON.stringify(constraints));
track.applyConstraints(constraints)
.then(() => {
console.log('applyConstraint success');
})
}
function getMedia(constraints) {
if (stream) {
stream.getTracks().forEach(track => {
track.stop();
});
}
navigator.mediaDevices.getUserMedia(constraints)
.then(gotStream)
}
</script>