Setting the granularity of the HTML5 audio event 'timeupdate'

后端 未结 2 815
庸人自扰
庸人自扰 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:21

    I'm sorry, but that's the way it works. From the html5 specs:

    Every 15 to 250ms, or whenever the MediaController's media controller position changes, whichever happens least often, the user agent must queue a task to fire a simple event named timeupdate at the MediaController.

    Also,

    The event thus is not to be fired faster than about 66Hz or slower than 4Hz (assuming the event handlers don't take longer than 250ms to run). User agents are encouraged to vary the frequency of the event based on the system load and the average cost of processing the event each time, so that the UI updates are not any more frequent than the user agent can comfortably handle while decoding the video.

    If you read through the specification, you can get the idea that timeupdate event is something of a "best effort" kind of event. It will fire when it can and always as long as it does not to affect performance too much.

    You could filter the events discarding some from time to time to smooth the arrival times, but I'm afraid it's not possible to do the opposite.

提交回复
热议问题