Skip to main content

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​

ParameterTypeDefaultDescription
soundsToRegister{ id: string; url: string | string[] }[]requiredThe 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 registerSound call: an entry without a usable url is skipped, and registering an id again replaces its urls.
  • Added in 6.2.0.

See also​