Skip to main content

setProgressUpdateInterval

Set how often progress events fire, in milliseconds. Raise it when a text label only needs a few updates a second, lower it for a smooth seek bar.

setProgressUpdateInterval(interval: number): void;

Parameters​

ParameterTypeDefaultDescription
intervalnumberrequiredMinimum time between two progress events for one sound, in milliseconds. The hub starts at 50.

Returns​

Nothing.

Example​

import { SoundHub, SoundEventsEnum } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');

// Four updates a second are plenty for a time label
soundHub.setProgressUpdateInterval(250);

soundHub.addEventListener(SoundEventsEnum.PROGRESS, (event) => {
timeLabel.textContent = `${event.currentTime?.toFixed(1)}s`;
}, { soundId: 'music' });

soundHub.play('music');

Good to know​

  • The setting is hub-wide, not per sound.
  • It applies to tracking that starts after the call. A sound that is already tracked keeps its old interval until its tracker restarts, for example on the next play(), resume() or seek().
  • Updates run on requestAnimationFrame, so an interval shorter than one frame (about 16 ms at 60 Hz) still gives one event per frame at most.
  • The value is not checked. 0 means an event on every frame.

See also​