-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios-demo.html
53 lines (48 loc) · 1.56 KB
/
ios-demo.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
<video id="player" autoplay muted playsinline> </video>
<button id="capture">Capture</button>
<canvas id="canvas" width=320 height=240></canvas>
<div id="message"></div>
<script>
const player = document.getElementById('player');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const messageDiv = document.getElementById('message');
const captureButton = document.getElementById('capture');
const constraints = {
video: {
facingMode: 'environment'
}
};
const log = message => {
console.log(message);
messageDiv.innerHTML = message;
}
captureButton.addEventListener('click', () => {
// Draw the video frame to the canvas.
context.drawImage(player, 0, 0, canvas.width, canvas.height);
});
const capture = function (constraints) {
// Attach the video stream to the video element and autoplay.
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
player.srcObject = stream;
});
}
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
capture({})
log("enumerateDevices() not supported. not using any constraints.");
}
else {
navigator.mediaDevices.enumerateDevices().then(function (devices) {
var m = devices.map(function (device) {
console.log(device)
return device.kind + ": " + device.label + " id = " + device.deviceId
}).join('<br>')
log(m);
capture(constraints)
}).catch(function (err) {
log(err.name + ": " + err.message);
capture({})
});
}
</script>