registerSounds
Register a whole list of sounds in one call. It calls registerSound for each entry, so nothing is fetched until you load a sound.
registerSounds(soundsToRegister: { id: string; url: string | string[] }[]): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
soundsToRegister | { id: string; url: string | string[] }[] | required | The sounds to register. Each url may be a list of alternatives. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
soundHub.registerSounds([
{ id: 'boss-music', url: ['/audio/boss.opus', '/audio/boss.mp3'] },
{ id: 'rain', url: '/audio/rain.mp3' },
]);
// When level seven starts
await soundHub.loadSound('boss-music');
soundHub.play('boss-music', { loop: true });
Good to know
- Each entry behaves exactly like a separate
registerSoundcall: an entry without a usable url is skipped, and registering an id again replaces its urls. - Added in 6.2.0.
See also
registerSound: register one sound.loadSounds: fetch a list of sounds right away instead.getLoadState: see whether a registered sound has been loaded.