currentTime进行搜索时延迟

currentTime进行搜索时延迟

本文介绍了使用HTML5 Audio.currentTime进行搜索时延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中使用Audio元素在很短的间隔内重复播放声音.IE和Chrome在使用currentTime时似乎没有延迟,但是Firefox的延迟非常明显.有没有办法让Firefox更快地寻找,或者有更好的替代方法来实现这一目标?

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>

推荐答案

HTML5 < audio> 元素尚未设计用于短时间间隔音频播放.它不适用于声音效果之类的用例.<音频> 设计用于由用户触发的类似音乐的交互式播放.

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.

使用 Web音频API 进行类似于音效的播放,从而为您提供有关播放延迟的一些保证.

Use Web Audio API for sound-effect-like playback which gives you some guarantees about the playback delays.

这篇关于使用HTML5 Audio.currentTime进行搜索时延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:34