Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/02/2014, 02:03
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 2 meses
Puntos: 574
Respuesta: Apagar dispositivo WebCam

Código Javascript:
Ver original
  1. function setStream(stream) {
  2.             var webcam....
  3. }
  4.  
  5. ....
  6.  
  7. function desconecta() {  if(estadoVideo == false) {return};
  8.             estadoVideo = false;
  9.             // window.URL.revokeObjectURL(objectURL);
  10.             webcam....
  11. }


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 original
  1. var estadoVideo = false;
  2.        ///Ahora será una variable accesible por todas las funciones
  3.        var webcam = document.getElementById("webcam");
  4.  
  5.         function hasGetUserMedia() {
  6.             navigator.getUserMedia = navigator.getUserMedia ||
  7.                 navigator.mozGetUserMedia ||
  8.                 navigator.webkitGetUserMedia ||
  9.                 navigator.msGetUserMedia;
  10.             if (navigator.getUserMedia) {return true;} else {return false;}
  11.         }
  12.        
  13.         function hasURL() {
  14.             window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
  15.             if (window.URL && window.URL.createObjectURL) {return true;} else {return false;}
  16.         }
  17.            
  18.         function error(e) { alert("Fallo en la aplicación. "+e); }
  19.        
  20.         function setStream(stream) {
  21.             /////////////Ojo que he comentado esto ----> var webcam = document.getElementById("webcam");
  22.             webcam.src = window.URL.createObjectURL(stream);
  23.             webcam.setAttribute("width", 160)
  24.             webcam.setAttribute("heigth", 120)
  25.             webcam.style.display="block";
  26.             webcam.play();
  27.         }
  28.        
  29.         function conectar() {
  30.             if (!hasGetUserMedia() || !hasURL()) {alert("Tu navegador no soporta getUserMedia()"); return false;}
  31.             navigator.getUserMedia( {video: true, audio: false}, setStream, error );
  32.             estadoVideo = true;
  33.             return true;
  34.         }
  35.  
  36. // Este es mi problema
  37.         function desconecta() {  if(estadoVideo == false) {return};
  38.             estadoVideo = false;
  39.             // window.URL.revokeObjectURL(objectURL);
  40.             webcam.mozSrcObject=null;
  41.             webcam.src="";
  42. //                webcam.removeChild(video);
  43.             webcam.style.display="none";
  44. //            webcam.pause();
  45.             webcam.stop();
  46.         }
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.

Última edición por quimfv; 27/02/2014 a las 02:08