Thursday, June 25, 2015

Web Cam Enable Application example

  1. <html>
  2. <head>
  3.  <meta charset="utf-8">
  4.  <title>JS Bin</title>
  5.  <script>
  6.     navigator.getUserMedia = ( navigator.getUserMedia ||
  7.                                navigator.webkitGetUserMedia ||
  8.                                navigator.mozGetUserMedia ||
  9.                                navigator.msGetUserMedia); 
  10.     if (navigator.getUserMedia) {
  11.         navigator.getUserMedia (
  12.             // constraints
  13.             {
  14.                 video: true,
  15.                 audio: false
  16.             },
  17.  
  18.             // successCallback
  19.             function(localMediaStream) {
  20.                 var video = document.querySelector('video');
  21.                 video.src = window.URL.createObjectURL(localMediaStream);
  22.             },
  23.  
  24.             // errorCallback
  25.             function(err) {
  26.                 console.log("The following error occured: " + err);
  27.             }
  28.         );
  29.     } else {
  30.         console.log("getUserMedia not supported");
  31.     }
  32.  </script>
  33. </head>
  34. <body >
  35.      <video width=200 height=200 id="video" controls autoplay></video>
  36. </body>
  37. </html>

No comments:

Post a Comment