Delays when seeking with HTML5 Audio.currentTime

大憨熊 提交于 2021-02-10 12:54:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!