Skip to main content

getSoundUrls

Get the urls a sound was registered or loaded with. When you passed a list of formats, you get the whole list back, not only the file the browser picked.

getSoundUrls(id: string): string[];

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of the sound.

Returns​

string[]: a copy of the url list on file. An empty array for an unknown id, for a stream, and after removeSound.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('music', ['/audio/theme.opus', '/audio/theme.m4a']);

soundHub.getSoundUrls('music'); // ['/audio/theme.opus', '/audio/theme.m4a']

Good to know​

  • The list is kept after unloadSound, which is what lets loadSound(id) reload without a url.
  • updateSoundUrl replaces the list with the new url.
  • Streams from loadStream do not record their url here.
  • Added in 6.2.0.

See also​

  • registerSound: put urls on file without loading.
  • canPlay: check which of the formats the browser can play.
  • loadSound: load from one url or a list.