问题
I use the Audio element in my JavaScript to play a sound repeatedly in short intervals. IE and Chrome seem to have no delay when using currentTime, but Firefox has a very noticable delay. Is there a way to have Firefox to seek faster, or a better alternative to accomplish this?
I use this (sample) script:
<script>
var audio = new Audio("Audio.ogg");
setInterval(function () {
audio.currentTime = 0;
audio.play();
}, 125);
</script>
回答1:
HTML5 <audio>
element has not been designed for short, intervalled, audio playback. It won't work for use cases like sound effects. <audio>
was designed for interactive music-like playback triggered by the user.
Use Web Audio API for sound-effect-like playback which gives you some guarantees about the playback delays.
来源:https://stackoverflow.com/questions/20657252/delays-when-seeking-with-html5-audio-currenttime