Skip to content
Permalink
Browse files

Examples now use modern navigator.mediaDevices

Solves #26
  • Loading branch information...
jcmellado committed Jan 29, 2018
1 parent 34ea629 commit 8a2d770f015e6cdb6f2810e701462a12b1106728
Showing with 92 additions and 55 deletions.
  1. +26 −15 samples/debug-posit/debug-posit.html
  2. +36 −23 samples/debug/debug.html
  3. +30 −17 samples/getusermedia/getusermedia.html
@@ -28,24 +28,35 @@
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia){
init();
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
};
function init(){
navigator.getUserMedia({video:true},
function (stream){
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function(constraints) {
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
}
return new Promise(function(resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function(stream) {
if ("srcObject" in video) {
video.srcObject = stream;
} else {
video.src = stream;
video.src = window.URL.createObjectURL(stream);
}
},
function(error){
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
}
);
@@ -23,34 +23,47 @@
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia){
function successCallback(stream){
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function(constraints) {
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
}
return new Promise(function(resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function(stream) {
if ("srcObject" in video) {
video.srcObject = stream;
} else {
video.src = stream;
video.src = window.URL.createObjectURL(stream);
}
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
}
);
function errorCallback(error){
}
imageData = context.getImageData(0, 0, camera.width, camera.height);
pixels = [];
detector = new AR.Detector();
navigator.getUserMedia({video:true}, successCallback, errorCallback);
imageData = context.getImageData(0, 0, camera.width, camera.height);
pixels = [];
detector = new AR.Detector();
debugImage = context.createImageData(camera.width, camera.height);
warpImage = context.createImageData(49, 49);
homographyImage = new CV.Image();
requestAnimationFrame(tick);
}
debugImage = context.createImageData(camera.width, camera.height);
warpImage = context.createImageData(49, 49);
homographyImage = new CV.Image();
requestAnimationFrame(tick);
}
function tick(){
@@ -19,28 +19,41 @@
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia){
function successCallback(stream){
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
} else {
video.src = stream;
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function(constraints) {
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
}
return new Promise(function(resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
function errorCallback(error){
}
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function(stream) {
if ("srcObject" in video) {
video.srcObject = stream;
} else {
video.src = window.URL.createObjectURL(stream);
}
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
}
);
navigator.getUserMedia({video: true}, successCallback, errorCallback);
detector = new AR.Detector();
detector = new AR.Detector();
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
}
function tick(){

0 comments on commit 8a2d770

Please sign in to comment.
You can’t perform that action at this time.