how to detect end of audio file using jquery and html5

后端 未结 3 968
别跟我提以往
别跟我提以往 2021-01-02 21:19

I\'ve got this jquery code and html to work OK for an English language training site.

$(document).ready(function() {
  $(\"p\").hover(
    function() {
             


        
3条回答
  •  无人及你
    2021-01-02 21:29

     ***var audioElement = null;***     
    
     $("p").click(function (event) {
    
        ***if (audioElement) {
            audioElement.pause();
         }***
    
    var element = $(this);
    var elementID = event.target.id;
    var oggVar = (elementID +".ogg");   
    audioElement = document.createElement('audio');
    audioElement.setAttribute('src', oggVar); 
    audioElement.load();
    audioElement.addEventListener("load", function() { 
        audioElement.play(); 
    }, true);
    audioElement.play();    
    
     }); 
    

提交回复
热议问题