2015-01-03 2 views
0

배경 오디오를 추가했지만 일시 중지하거나 멈출 수 없습니다. 어떻게해야합니까?이 코드는 완벽하게 작동하지만 일시 중지하고 작동하지 않습니다. 일시 중지가 사용되었습니다. 버튼이 작동하지 않습니다.html jquery에서 배경 오디오를 일시 중지하고 중지하는 방법

MY JQuery와는

 $(window).load(function() { 
      var collection = [];// final collection of sounds to play 
      var loadedIndex = 0;// horrible way of forcing a load of audio sounds 

    // remap audios to a buffered collection 
      function init(audios) { 
       for (var i = 0; i < audios.length; i++) { 
        var audio = new Audio(audios[i]); 
        collection.push(audio); 
        buffer(audio); 
       } 
      } 

    // did I mention it's a horrible way to buffer? 
      function buffer(audio) { 
       if (audio.readyState == 4) 
        return loaded(); 
       setTimeout(function() { 
        buffer(audio) 
       }, 100); 
      } 

    // check if we're leady to dj this 
      function loaded() { 
       loadedIndex++; 
       if (collection.length == loadedIndex) 
        playLooped(); 
      } 

    // play and loop after finished 
      function playLooped() { 
       var audio = Math.floor(Math.random() * (collection.length)); 
       audio = collection[audio]; 
       audio.play(); 

       setTimeout(audio.duration * 1000); 
      } 


    // the songs to be played! 
      init([ 
       'jingle/image1.mp3', 
       'jingle/image2.mp3', 
       'jingle/image3.mp3', 

      ]); 

     }); 

답변

0

당신은 일시 중지하거나 autdio를 중지 버튼이나 URL을해야합니다. 예 :

<a href = "javascript:;" class ="stop" onclick="pause_stop(audio)">Pause/Stop</a> 

function pause_stop(this) 
{ 
if(getAttribute("rel") == 'stopped') 
    this.setAttribute("rel", "stopped"); 
    this.pause(); 

} 
else 
{ 
this.setAttribute("rel", ""); 
    this.play(); 
} 

}

+0

pause_stop가 정의되어 있지 않습니다 –

관련 문제