Skip to main content

getSoundIds

Get the ids of every sound and stream the hub holds. Useful for a debug panel or for looping over everything that is loaded.

getSoundIds(): string[];

Parameters​

This method takes no parameters.

Returns​

string[]: the ids of the buffered sounds, followed by the ids of the streams. An empty array when nothing is loaded.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSounds([
{ id: 'music', url: '/audio/theme.mp3' },
{ id: 'click', url: '/audio/click.mp3' },
]);

soundHub.play('click', { overlap: true });

console.log(soundHub.getSoundIds()); // ['music', 'click', 'click:1']

Good to know​

  • Overlapping instances show up as <id>:<n>, and sprite sounds made by setSoundSprite as <id>_<key>. Finished instances are cleared the next time the same sound plays with overlap.
  • Sounds that are only registered with registerSound are not included.
  • The array is a copy, so changing it does not affect the hub.

See also​