test media capture
This commit is contained in:
parent
d0ab9fc114
commit
595679e869
17
index.html
Normal file
17
index.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Media recorder example</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<video autoplay></video>
|
||||||
|
<script src="index.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
23
index.js
Normal file
23
index.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
function hasGetUserMedia() {
|
||||||
|
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDeviceAccess() {
|
||||||
|
const constraints = {
|
||||||
|
video: true,
|
||||||
|
audio: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const video = document.querySelector("video");
|
||||||
|
|
||||||
|
// todo avoid to play sound (only display video feedback)
|
||||||
|
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
|
||||||
|
video.srcObject = stream;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasGetUserMedia()) {
|
||||||
|
getDeviceAccess()
|
||||||
|
} else {
|
||||||
|
alert("getUserMedia() is not supported by your browser");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user