Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Render video from js into html

I’m new here and have a question. How can I render the webcam video from JavaScript into HTML? I want to scan QR-Codes in my browser and while scanning there should be the video from the camera for better user experience (easier to find the qr-code). For scanning the QR-Codes, I use Instascan. My code looks something like this:

HTML:

<div class="video-container">
   <div class="overlay-box">
      <video id="preview"></video>
   </div>
</div>

JavaScript:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });

// When starting scanning, activate via css
document.getElementById("preview").style.display = "block";

// When stopping scanning, deactivate via css
document.getElementById("preview").style.display = "none";

I tried without the css stuff, but that was not a problem. It should be a problem with the scanner ig…

Expecting: that it render it into the html file that I can see the camera output while scanning

Thanks for every help!
PS: If it’s an important information (idk); its inside a Django project

>Solution :

if i understood right, you are trying to use the user’s webcam to read the QR code, is that right?
If so, you can try to use the navigator.mediaDevices.getUserMedia() to handle it.
you can have more information about this method here:
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading