Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.79 KB | None | 0 0
  1. <div style="text-align:center;">
  2. <video id="screenshot-stream" class="videostream" autoplay=""></video>
  3. <img id="screenshot" src="">
  4. <canvas id="screenshot-canvas" style="display:none;"></canvas>
  5. <p><button id="screenshot-button">Capture</button> <button id="screenshot-stop-button">Stop</button></p>
  6. </div>
  7.  
  8.  
  9.  
  10. <script>
  11.  
  12. function onFailSoHard(e){if(e.code==1){alert('User denied access to their camera');}else{alert('getUserMedia() not supported in your browser. Please use chrome, firefox, or safari.');}}
  13.  
  14.  
  15. (function(){var video=document.querySelector('#screenshot-stream');
  16.             var button=document.querySelector('#screenshot-button');
  17.             var canvas=document.querySelector('#screenshot-canvas');
  18.             var img=document.querySelector('#screenshot');
  19.             var ctx=canvas.getContext('2d');
  20.             var localMediaStream=null;
  21.             function sizeCanvas(){setTimeout(function(){canvas.width=video.videoWidth;canvas.height=video.videoHeight;img.height=video.videoHeight;img.width=video.videoWidth;},100);}
  22.             function snapshot(){ctx.drawImage(video,0,0);img.src=canvas.toDataURL('image/webp');}
  23.                 if(localMediaStream){snapshot();return;}
  24.                 if(navigator.getUserMedia){navigator.getUserMedia('video',function(stream){video.src=stream;localMediaStream=stream;sizeCanvas();button.textContent='Take Shot';},onFailSoHard);}
  25.                 else if(navigator.webkitGetUserMedia){navigator.webkitGetUserMedia({video:true},function(stream){video.src=window.webkitURL.createObjectURL(stream);localMediaStream=stream;sizeCanvas();button.textContent='Take Shot';},onFailSoHard);}
  26.                 else{onFailSoHard({target:video});}
  27.             video.addEventListener('click',snapshot,false);
  28.             document.querySelector('#screenshot-stop-button').addEventListener('click',function(e){
  29.                 video.pause();localMediaStream.stop();},false);})();</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement