Skip to main content

startProgressTracking

Start dispatching progress events for a playing sound. You rarely need to call it: with the default trackProgress: true in the config, every play() starts tracking by itself. Call it when you turned tracking off and want it for one sound.

startProgressTracking(id: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of a playing sound, stream or overlapping instance.

Returns​

Nothing.

Example​

import { SoundHub, SoundEventsEnum } from 'soundhub';

const soundHub = new SoundHub({ trackProgress: false });
await soundHub.loadSound('music', '/audio/theme.mp3');

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

soundHub.play('music');
soundHub.startProgressTracking('music');

Good to know​

  • Each event is SoundEventsEnum.PROGRESS ('progress') with currentTime, duration, progress, a progressInfo object (see soundProgressStateInfo) and the full getSoundState snapshot as state.
  • Updates run on requestAnimationFrame, at most once per interval (50 ms by default, see setProgressUpdateInterval). Browsers pause animation frames in a background tab, so no events arrive there.
  • Tracking stops by itself when the sound pauses, stops or ends, and on the first update if the sound is not playing. Call it after play(), not before.
  • Calling it again for the same id replaces the running tracker, so there are never two.
  • The tracker also enforces the duration play option: when the range is used up it ends, loops or pauses the sound (with pauseAtDurationReached).

See also​