From 4fea8e9ff1d9da438f25dbce3eb3b9b8126726d7 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 17 Oct 2020 10:25:27 -0400 Subject: [PATCH] fixed webcam initialization --- demo/browser.js | 13 ++++++++----- demo/index.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/demo/browser.js b/demo/browser.js index 35ecca38..81869c61 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -98,11 +98,13 @@ async function setupCamera() { const canvas = document.getElementById('canvas'); const output = document.getElementById('log'); const live = video.srcObject ? ((video.srcObject.getVideoTracks()[0].readyState === 'live') && (video.readyState > 2) && (!video.paused)) : false; - log(`Setting up camera: live: ${live} facing: ${ui.facing}`); + let msg = `Setting up camera: live: ${live} facing: ${ui.facing}`; + output.innerText += `\n${msg}`; + log(msg); // setup webcam. note that navigator.mediaDevices requires that page is accessed via https if (!navigator.mediaDevices) { - const msg = 'Camera access not supported'; - output.innerText += '\n' + msg; + msg = 'Camera access not supported'; + output.innerText += `\n${msg}`; log(msg); return null; } @@ -127,7 +129,8 @@ async function setupCamera() { if (live) video.play(); ui.busy = false; // do once more because onresize events can be delayed or skipped - if (video.width !== window.innerWidth) await setupCamera(); + if (video.width > window.innerWidth) await setupCamera(); + output.innerText += `\nCamera resolution: ${video.width} x ${video.height}`; resolve(video); }; }); @@ -229,7 +232,7 @@ async function detectVideo() { const canvas = document.getElementById('canvas'); ui.baseFont = ui.baseFontProto.replace(/{size}/, '1.2rem'); ui.baseLineHeight = ui.baseLineHeightProto; - if (!video.paused) { + if ((video.srcObject !== null) && !video.paused) { document.getElementById('log').innerText += '\nPaused ...'; video.pause(); } else { diff --git a/demo/index.html b/demo/index.html index d49c24cf..3e6e2955 100644 --- a/demo/index.html +++ b/demo/index.html @@ -20,7 +20,7 @@ - +
Human library