2014-06-12 5 views
0

나는 html로 소리가 나도록 노력하고있다. 5. sound.loop = true; 작동하지만 소리가 끝나면 루핑 사이에 침묵이 있습니다. 어떻게 피할 수 있습니까? 덕분에 코드는 다음과 같습니다.어떻게 자바 스크립트에서 오디오 루프 지연을 피하기 위해?

<audio id="ruido"> 
<source src="ruido.ogg" type="audio/ogg"> 
<source src="ruido.mp3" type="audio/mpeg"> 
Your browser does not support the audio element. 
</audio> 
<script> 
    var sound = document.getElementById("ruido"); 
    sound.loop = true; 
    sound.play(); 
</script> 

답변

0

'종료 됨'이벤트가 호출되면 JavaScript 함수를 사용하여 루프 할 수 있습니다.

<audio id="loopMe" controls preload> 
    <source src="ruido.ogg" type="audio/ogg"> 
    <source src="ruido.mp3" type="audio/mpeg"> 
</audio> 

document.getElementById('loopMe').addEventListener('ended', function(){ 
this.currentTime = 0; 
this.play(); 
}, false); 

또는 더 나은 아직은 SeamlessLoop 라이브러리를 시도 특정 브라우저 오디오 API를하지 않고 HTML5/자바 스크립트 원활한/끊김없는 오디오 루프를 재현.

+0

나는 SeamlessLoop 라이브러리를 사용해 보았지만 위대한 것처럼 보였지만 내 오디오 파일의 URI를 어떻게 알 수 있는지 알지 못했습니다. 코딩을위한 참고 자료로 Seamless를 사용하겠습니다. 내가 본 것까지 모든 네비게이터는 루프에 자신의 지체가 있습니다. – DaNoiseMan

관련 문제