El código HTML que les agregué activa una WebCam con lo básico.
Mi problema es el siguiente:
Cuando desactivo, desconecto, apago la webcam; logro esconderla del navegador, pero sigue prendida. Este es mi problema.
Yo desearía cerrar totalmente el stream. Pero no logro hacerlo. Le ponga lo que le ponga me sigue mostrando la figura de color verde de la WebCam en el Navegador y si pincho en ella me dice que: "Esta compartiendo el dispositivo con mi pagina".
Te agradezco cualquier orientación que puedas darme.
Código HTML:
Ver original
<!DOCTYPE html> <html lang="es"> <html> <head> <meta charset="UTF-8"> <style> *{margin:0px; padding:0px;} body { background-color:RGB(215,201,168); } </style> </head> <body> <!-- onload="onLoad()"> --> <br> <input type="button" onclick="conectar()" value="Selecciona WebCam"/> <input type="button" onclick="desconecta()" value="Desconectar"/> </body> <script> estadoVideo = false; 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) { 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(); } </script> </html>
Como ven en la última función le ponga lo que sea el resultado es el mismo.