isSoundLoaded
Check whether a sound is loaded. It is the quick yes or no; getLoadState tells you more when you need to show a spinner or a retry button.
isSoundLoaded(id: string): boolean;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream to check. |
Returns
boolean: true when the sound is decoded and stored, or the id is a stream. false for an unknown id and for a sound that is registered, loading, failed or unloaded.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
soundHub.registerSound('music', '/audio/theme.mp3');
soundHub.isSoundLoaded('music'); // false
await soundHub.loadSound('music');
soundHub.isSoundLoaded('music'); // true
soundHub.unloadSound('music');
soundHub.isSoundLoaded('music'); // false
Good to know
- It gives the same answer as
hasSound. - It never logs an error for an unknown id.
See also
getLoadState: unloaded, loading, loaded or error.hasSound: the same check under another name.loadSound: load a sound.