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 bysetSoundSpriteas<id>_<key>. Finished instances are cleared the next time the same sound plays withoverlap. - Sounds that are only registered with
registerSoundare not included. - The array is a copy, so changing it does not affect the hub.
See also
getSoundCount: the same entries, counted.hasSound: check one id.getSound: the sound object behind an id.