Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- js.camera.setup = function(){
- var div = document.createElement('div');
- var video = document.createElement('video');
- var canvas = document.createElement('canvas');
- video.autoplay = true;
- video.addEventListener('loadedmetadata', function(e){
- var canvas = navigator.camera._canvas;
- div.style.display = '';
- //console.debug(e.target.videoHeight);
- //console.debug(e.target.videoWidth);
- canvas.width = '640';
- canvas.height = '480';
- // camera not ready???
- setTimeout(function() { navigator.camera._pictureTake(); }, 6000);
- });
- div.style.top="100px";
- div.style.width="600px";
- canvas.style.top = '0px';
- canvas.style.left = '600px';
- div.appendChild(video);
- div.appendChild(canvas);
- navigator.camera = cordova.require('cordova/plugin/CameraConstants');
- navigator.camera._video = video;
- navigator.camera._canvas = canvas;
- navigator.camera._stream;
- navigator.camera.getPicture = function(successCallback, errorCallback, options) {
- div.style.position="absolute";
- div.style.zIndex="60000";
- canvas.style.position = 'absolute';
- this._pictureTake = function() {
- var browserCam = navigator.camera;
- // TODO: error handling?
- // destinationType (URI only)
- // quality (no support)
- // encodingType (png only)
- var ctx = browserCam._canvas.getContext('2d');
- // TODO: support width & height here...
- ctx.drawImage(browserCam._video, 0, 0);
- var uri = browserCam._canvas.toDataURL('image/png');
- div.style.display = 'none';
- browserCam._stream.stop(); // stop stream
- browserCam._stream = null;
- successCallback.call(this, uri);
- };
- navigator.getUserMedia({video: true}, function(stream) {
- navigator.camera._stream = stream;
- video.src = window.URL.createObjectURL(stream);
- }, function(e){ errorCallback.call(this, e); } );
- };
- MV.dom.getBody().appendChild(div);
- };
Advertisement
Add Comment
Please, Sign In to add comment