2012-06-12 17 views
5

Estoy usando una etiqueta de video y vinculándola usando bind o live. En ambos casos no funciona. Debajo está mi código. Puedo estar haciendo algo mal y no puedo atraparlo.No se pueden enlazar los eventos de video usando Jquery

  <video width="videoWidth" 
      height="videoHeight" 
      poster="../Poster/poster.png" 
      id="videoId" 
      controls="controls" 
      muted="true"  
      seeking="true" 
      paused="true" > 

      <source src="../video/trailer.mp4" type="video/mp4"/>    
      <source src="../video/trailer.ogv" type="video/ogv"/> 
      <source src="../video/trailer.webm" type="video/webm"/> 
       Your browser does not support the video tag. 
      </video> 

Aquí se incluye el archivo JS para enlazar los eventos.

$("#videoId").bind('ended',function() { 
      alert("Entered"); 
     }); 

ACTUALIZACIÓN

Estoy actualizando JS anterior y ahora su trabajo para todos Events.Now video que estabas atascado en el evento de error en el evento se disparará basado en eventos code.May ser que me equivoque al escribir el código de error, pero evento no es mi working.Below JS

$(document).ready(function(){ 
     $("#videoId").bind('play',function() { 
      alert("Play"); 
     }); 

     $("#videoId").bind('canplay',function() { 
      alert("Can Play"); 
     }); 

     $("#videoId").bind('empited',function() { 
      alert("Empited"); 
     }); 

     $("#videoId").bind('ended',function() { 
      alert("Ended"); 
     }); 

     $("#videoId").bind('loadstart',function() { 
      alert("Load Start"); 
     }); 

     $("#videoId").bind('pause',function() { 
      alert("Pause"); 
     }); 

     $("#videoId").bind('playing',function() { 
      alert("Playing"); 
     }); 

     $("#videoId").bind('progress',function() { 
      alert("Progress"); 
     }); 

     $("#videoId").bind('suspend',function() { 
      alert("Suspend"); 
     }); 

     $("#videoId").bind('volumechange',function() { 
      alert("Volume"); 
     }); 

     $("#videoId").bind('waiting',function() { 
      alert("waiting"); 
     }); 
     $("#videoId").bind('error',function(e,ui) { 
      switch (e.target.error.code) { 
      case e.target.error.MEDIA_ERR_ABORTED: 
       alert('You aborted the video playback.'); 
       break; 
      case e.target.error.MEDIA_ERR_NETWORK: 
       alert('A network error caused the video download to fail part-way.'); 
       break; 
      case e.target.error.MEDIA_ERR_DECODE: 
       alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.'); 
       break; 
      case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: 
       alert('The video could not be loaded, either because the server or network failed or because the format is not supported.'); 
       break; 
      default: 
       alert('An unknown error occurred.'); 
       break; 
      } 
      //alert("Error Code : "+event.target.error.code); 
     }); 

     }); 

En Consola estoy recibiendo 'Get'.

+0

que debería funcionar. ¿Tu código se está ejecutando en un controlador de eventos listo para DOM? –

+0

cualquier error en la consola? – Neil

+0

Sí, funciona en el controlador listo DOM. –

Respuesta

3

Esto alertará a todos los objetos en el objeto de error en el elemento de vídeo

$("video").on("error", function(err) { 
    for (var i in err.currentTarget.error) { 
     alert(i + ": " + err.currentTarget.error[i]); 
    } 
}); 
Cuestiones relacionadas