Setting the granularity of the HTML5 audio event 'timeupdate'

后端 未结 2 816
庸人自扰
庸人自扰 2020-11-29 06:09

I\'m trying to create a simple looping feature using HTML5 audio and have a very primitive solution as follows:

$(audio).bind(\'timeupdate\', function() {
           


        
2条回答
  •  囚心锁ツ
    2020-11-29 06:18

    It should be noted that you can read the currentTime property of a video much more often. If time is really critical, and you can live with a little bit of uncertainty, you can try this instead.

    It is, however, a lot less elegant than using the tag's own timeupdate event.

    setInterval(function () {
        console.log(audio.currentTime); // will get you a lot more updates.
    }, 30);
    

    In this case, you'll have to manage the interval yourself, make sure that you clear it before nulling the audio element. But it is a possibility.

    I'm using this approach on a video element, but it should apply here, too.

提交回复
热议问题