Forum Moderators: open

Message Too Old, No Replies

HTML5 image capture

         

Gowri pandiyan

10:27 am on Jan 28, 2016 (gmt 0)

10+ Year Member



Hi,

What's wrong with below code? It isn't working in any browser, but code seems to be fine to me. OR is there any browser compatible issue in this code. As far as I know, It should work on Crome atleast, but it isn't.

<video id="video" width="640" height="480" autoplay></video>
<button id="snap" class="sexyButton">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>

<script>

// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};

// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
} else if(navigator.mozGetUserMedia) { // WebKit-prefixed
navigator.mozGetUserMedia(videoObj, function(stream){
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}

// Trigger photo take
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
}, false);

</script>

birdbrain

5:12 pm on Jan 28, 2016 (gmt 0)



Hi there Gowri pandiyan,

The code worked OK for me in these browsers...

  1. IE11
  2. Firefox 44.0
  3. Chrome 48.0
  4. Opera 34.0

...when I used this HTML...

<video id="video" width="640" height="480" autoplay>
<source src="QuentinSommerville.mp4" type="video/mp4">
</video>


birdbrain

Gowri pandiyan

4:56 am on Jan 29, 2016 (gmt 0)

10+ Year Member



Thanks Bird for your reply! One quick question, will it work in mobile phone browsers?

tangor

5:05 am on Jan 29, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should, but the viewport size might be too large for some mobiles....

Gowri pandiyan

5:27 am on Jan 29, 2016 (gmt 0)

10+ Year Member



And also please let me know if below code will work to capture image from mobile camera and allow to upload the captured image.

<input type="file" name="myfile" id="myfile" accept="image/*;capture=camera"/>

tangor

5:30 am on Jan 29, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you not downloading vids from phone to your system? Most phones do that without any code involved. Or am I missing something in your question?

Gowri pandiyan

5:49 am on Jan 29, 2016 (gmt 0)

10+ Year Member



Ideally, I would like to have an option in my mobile-specific-website to capture users' picture from their mobile camera and allow them to upload it into our server. Is it possible with any of above code? As I tested, It is not working as espected. Please suggest.

Gowri pandiyan

6:05 am on Feb 1, 2016 (gmt 0)

10+ Year Member



Any update?

tangor

6:52 am on Feb 1, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you set up an upload function? Do your users know what kind of file to send you? I don't do mobile so I have no clue in that regard, only what "old school" file sharing looks like. Maybe someone else will chime in in that regard.

Gowri pandiyan

5:50 am on Feb 2, 2016 (gmt 0)

10+ Year Member



Thanks for your help, Tangor! I have tested the second code with some jquery support. It is working great in all the mobiles expect windows phone.

Gowri pandiyan

6:27 am on Feb 2, 2016 (gmt 0)

10+ Year Member



Corrected typo!

Thanks for your help, Tangor! I have tested the second code with some jquery support. It is working great in all the mobiles except windows phone.