From 595679e86981082ec31f09438561950a9bff710e Mon Sep 17 00:00:00 2001 From: Tropicananass Date: Fri, 25 Feb 2022 16:40:14 +0100 Subject: [PATCH] test media capture --- index.html | 17 +++++++++++++++++ index.js | 23 +++++++++++++++++++++++ style.css | 0 3 files changed, 40 insertions(+) create mode 100644 index.html create mode 100644 index.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 0000000..a6626db --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + + + Media recorder example + + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..4de8321 --- /dev/null +++ b/index.js @@ -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"); +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..e69de29