Skip to main content

getSoundCount

Get how many sounds and streams the hub holds. Handy for a debug overlay or to spot instances piling up.

getSoundCount(): number;

Parameters​

This method takes no parameters.

Returns​

number: the number of buffered sounds plus the number of streams. 0 when nothing is loaded.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.getSoundCount(); // 1

soundHub.play('click', { overlap: true });
soundHub.getSoundCount(); // 2: 'click' and 'click:1'

Good to know​

  • Every overlapping instance and every sprite sound counts as an entry of its own.
  • Registered sounds that were never loaded do not count.
  • A count that keeps climbing usually means instances that are still playing or paused. The maxInstancesPerSound option in SoundHubConfig puts a ceiling on them.

See also​

  • getSoundIds: the ids behind the count.
  • isReady: whether at least one sound is loaded and the context is running.