I'm using HTML5 to get photo from Webcam. Then I write a Camera object to handle this, as below:
function Camera(width) {
this.video = $("video#videoInput");
this.canvas= $("#editor");
this.width = 0;
this.height = 0;
this.hasGetUserMedia = function() {/*check camera available*/};
var errorCallback = function(e) {};
this.turnOn = function() {
if (this.hasGetUserMedia()) {
// Good to go!
navigator.getUserMedia({video: true}, function(stream) {
this.video[0].src = window.URL.createObjectURL(stream);
//this is video property of Camera
}, errorCallback);
}
}
}
var cam = new Camera();
cam.turnOn()
But I can access to Camera properties in some methods, example Camera.turnOn(). when I use this.video, console output undefined error. I know this in this case means navigator object.
So, how do I access to Camera properties inside callback function of another object?