Guest User

Untitled

a guest
Dec 12th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. js.camera.setup = function(){
  2.  
  3.     var div = document.createElement('div');
  4.     var video = document.createElement('video');
  5.     var canvas = document.createElement('canvas');
  6.    
  7.     video.autoplay = true;
  8.      video.addEventListener('loadedmetadata', function(e){
  9.         var canvas = navigator.camera._canvas;
  10.         div.style.display = '';
  11.         //console.debug(e.target.videoHeight);
  12.         //console.debug(e.target.videoWidth);
  13.        
  14.         canvas.width = '640';
  15.         canvas.height = '480';
  16.        
  17.         // camera not ready???
  18.         setTimeout(function() { navigator.camera._pictureTake(); }, 6000);
  19.     });
  20.    
  21.     div.style.top="100px";
  22.     div.style.width="600px";
  23.     canvas.style.top = '0px';
  24.     canvas.style.left = '600px';
  25.  
  26.     div.appendChild(video);
  27.     div.appendChild(canvas);
  28.  
  29.     navigator.camera = cordova.require('cordova/plugin/CameraConstants');
  30.     navigator.camera._video = video;
  31.     navigator.camera._canvas = canvas;
  32.     navigator.camera._stream;
  33.     navigator.camera.getPicture = function(successCallback, errorCallback, options) {
  34.        
  35.         div.style.position="absolute";
  36.         div.style.zIndex="60000";
  37.         canvas.style.position = 'absolute';
  38.  
  39.         this._pictureTake = function() {
  40.             var browserCam = navigator.camera;
  41.             // TODO: error handling?
  42.             // destinationType (URI only)
  43.             // quality (no support)
  44.             // encodingType (png only)
  45.             var ctx = browserCam._canvas.getContext('2d');
  46.  
  47.             // TODO: support width & height here...
  48.             ctx.drawImage(browserCam._video, 0, 0);
  49.             var uri = browserCam._canvas.toDataURL('image/png');
  50.             div.style.display = 'none';
  51.  
  52.             browserCam._stream.stop(); // stop stream
  53.             browserCam._stream = null;
  54.  
  55.             successCallback.call(this, uri);
  56.         };
  57.  
  58.         navigator.getUserMedia({video: true}, function(stream) {
  59.  
  60.             navigator.camera._stream = stream;
  61.             video.src = window.URL.createObjectURL(stream);
  62.  
  63.         }, function(e){ errorCallback.call(this, e); } );
  64.  
  65.     };
  66.     MV.dom.getBody().appendChild(div);
  67. };
Advertisement
Add Comment
Please, Sign In to add comment