user2781785
user2781785

Reputation:

How to open camera in winJs

i am working for a face detection mechanism in winJs starting from the basic. What is the mechanism to open a Camera in winJs and in which tag to show the video.

This is the code i know till now

var Capture = Windows.Media.Capture;
var mediaCapture = new Capture.MediaCapture();
mediaCapture.initializeAsync();

How to show in a Div the same.

Upvotes: 1

Views: 1140

Answers (1)

Anobik
Anobik

Reputation: 4899

here's the html for the same.

function init() {
            livePreview = document.getElementById("live-preview");
            startCamera();
        }

        function startCamera() {
            try {
                mediaCapture = new Capture.MediaCapture();
                mediaCapture.initializeAsync().then(function () {
                    livePreview.src = URL.createObjectURL(mediaCapture);
                    livePreview.play();
                });
            } catch(exception) {
                Windows.UI.Popups.MessageDialog(exception.message, "Error").showAsync();
            } 

        }

HTML

<div id="application" style="width:100%; height: 180px; overflow: hidden; background: #222;">
            <video id="live-preview" style="display : none; width:100%; height: 180px; overflow: hidden;"></video>
        </div>

these were some of the variables Select appropriate ones

 var Capture = Windows.Media.Capture;


// Globals
var mediaCapture;
var recording = false;
var livePreview;
var activation = Windows.ApplicationModel.Activation;

Upvotes: 2

Related Questions