-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebviewcamera.html
61 lines (40 loc) · 1.8 KB
/
webviewcamera.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
<html><head></head><body>
<h1>Take Photo</h1>
<div id="imageblock1">
<img id="blabla1" width="150" height="150"> </div>
<h1>Capturing Video...</h1>
<button onclick="play()">Click to show</button><br>
<video heigh="150" width="150" playsinline="" autoplay=""></video>
<script>
function gotMedia(mediaStream) {
console.log('getUserMedia() got stream:', mediaStream);
const mediaStreamTrack = mediaStream.getVideoTracks()[0];
const imageCapture = new ImageCapture(mediaStreamTrack);
console.log(imageCapture);
const img = document.querySelector('img');
imageCapture.takePhoto()
.then(blob => {
img.src = URL.createObjectURL(blob);
img.onload = () => { URL.revokeObjectURL(this.src); }
})
.catch(error => console.error('takePhoto() error:', error.name, " ", error.message));
const gumVideo = document.querySelector('video');
gumVideo.srcObject = mediaStream;
}
function play(){
const gumVideo = document.querySelector('video');
gumVideo.play();
}
window.addEventListener('load', async () => {
const constraints = {
video: {
width: 150, height: 150
}
};
console.log('Using media constraints:', constraints);
navigator.mediaDevices.getUserMedia(constraints)
.then(gotMedia)
.catch(error => console.error('getUserMedia() error:', error.name, " ", error.message));
});
</script>
</body></html>