Código Javascript
:
Ver originalfunction setStream(stream) {
var webcam....
}
....
function desconecta() { if(estadoVideo == false) {return};
estadoVideo = false;
// window.URL.revokeObjectURL(objectURL);
webcam....
}
webcam es una variable local de la función
setStream luego dificilmente puedes acceder a ella des de otra función... no? No te esta dando un error por variable no definida?
No puedo intentarlo aqui pero
Código Javascript
:
Ver originalvar estadoVideo = false;
///Ahora será una variable accesible por todas las funciones
var webcam = document.getElementById("webcam");
function hasGetUserMedia() {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia ||
navigator.msGetUserMedia;
if (navigator.getUserMedia) {return true;} else {return false;}
}
function hasURL() {
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
if (window.URL && window.URL.createObjectURL) {return true;} else {return false;}
}
function error(e) { alert("Fallo en la aplicación. "+e); }
function setStream(stream) {
/////////////Ojo que he comentado esto ----> var webcam = document.getElementById("webcam");
webcam.src = window.URL.createObjectURL(stream);
webcam.setAttribute("width", 160)
webcam.setAttribute("heigth", 120)
webcam.style.display="block";
webcam.play();
}
function conectar() {
if (!hasGetUserMedia() || !hasURL()) {alert("Tu navegador no soporta getUserMedia()"); return false;}
navigator.getUserMedia( {video: true, audio: false}, setStream, error );
estadoVideo = true;
return true;
}
// Este es mi problema
function desconecta() { if(estadoVideo == false) {return};
estadoVideo = false;
// window.URL.revokeObjectURL(objectURL);
webcam.mozSrcObject=null;
webcam.src="";
// webcam.removeChild(video);
webcam.style.display="none";
// webcam.pause();
webcam.stop();
}