Every line of 'access mobile camera using javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
3 function captureCamera(callback) { 4 getUserMedia({ 5 video: audio, 6 constraints: { audio: true, video: false }, 7 onsuccess: function (stream) { 8 global.clientStream = stream; 9 10 audio.show().play(); 11 12 setTimeout(function() { 13 audio.css('-webkit-transform', 'rotate(360deg)'); 14 }, 1000); 15 16 $('.visible', true).hide(); 17 18 callback && callback(); 19 }, 20 onerror: function () { 21 alert('Either you not allowed access to your microphone/webcam or another application already using it.'); 22 } 23 }); 24 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
24 function captureCamera(callback) { 25 navigator.mediaDevices.getUserMedia({ video: true }).then(function(camera) { 26 callback(camera); 27 }).catch(function(error) { 28 alert('Unable to capture your camera. Please check console logs.'); 29 console.error(error); 30 }); 31 }
25 async function setupCamera() { 26 if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { 27 alert( 28 'Browser API navigator.mediaDevices.getUserMedia not available'); 29 } 30 31 const video = document.getElementById('video'); 32 33 const mobile = isMobile(); 34 try{ 35 const stream = await navigator.mediaDevices.getUserMedia({ 36 'audio': false, 37 'video': { 38 facingMode: 'user', 39 width: mobile ? undefined : videoWidth, 40 height: mobile ? undefined : videoHeight, 41 }, 42 }); 43 44 video.srcObject = stream; 45 }catch(err){alert(err)} 46 return new Promise((resolve) => { 47 video.onloadedmetadata = () => { 48 resolve(video); 49 }; 50 }); 51 }
47 async function setupCamera() { 48 if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { 49 throw new Error( 50 'Browser API navigator.mediaDevices.getUserMedia not available'); 51 } 52 53 const video = document.getElementById('video'); 54 const stream = await navigator.mediaDevices.getUserMedia({ 55 'audio': false, 56 'video': { 57 facingMode: 'user', 58 }, 59 }); 60 video.srcObject = stream; 61 62 return new Promise((resolve) => { 63 video.onloadedmetadata = () => { 64 resolve(video); 65 }; 66 }); 67 }
10 async getCamera() { 11 const camera = await this.map.getCamera(); 12 13 console.log(camera); 14 alert('Current camera', JSON.stringify(camera, null, 2), [{ text: 'OK' }], { 15 cancelable: true, 16 }); 17 }
119 setVideoSource(stream) { 120 if ('srcObject' in this.videoElement) { 121 this.videoElement.srcObject = stream; 122 } 123 else { 124 // TODO: Bacon: Check if needed 125 this.videoElement['src'] = window.URL.createObjectURL(stream); 126 } 127 }
203 startCamera(options: CameraPreviewOptions): Promise<any> { 204 return; 205 }
61 openCamera() { 62 const options: CameraOptions = { 63 quality: 100, 64 correctOrientation: true, 65 cameraDirection: 1 66 }; 67 this.camera 68 .getPicture(options) 69 .then(imageData => { 70 console.log("IMAGE DATA IS", imageData); 71 this.presentToast("Image chosen successfully"); 72 this.convertToBase64(imageData, true); 73 }) 74 .catch(e => { 75 console.log("Error while picking from camera", e); 76 }); 77 }
58 async setupCamera() { 59 if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { 60 throw new Error( 61 'Browser API navigator.mediaDevices.getUserMedia not available'); 62 } 63 64 const video = this.htmlElements.video; 65 video.width = videoWidth; 66 video.height = videoHeight; 67 68 const mobile = this.isMobile(); 69 const stream = await navigator.mediaDevices.getUserMedia({ 70 'audio': false, 71 'video': { 72 facingMode: 'user', 73 width: mobile ? undefined : videoWidth, 74 height: mobile ? undefined : videoHeight, 75 }, 76 }); 77 video.srcObject = stream; 78 79 return new Promise((resolve) => { 80 video.onloadedmetadata = () => { 81 resolve(video); 82 }; 83 }); 84 }
154 function captureUserMedia(success_callback) { 155 var session = { 156 audio: true, 157 video: true 158 }; 159 160 navigator.getUserMedia(session, success_callback, function(error) { 161 alert('Unable to capture your camera. Please check console logs.'); 162 console.error(error); 163 }); 164 }