isStream
Check whether an id was loaded with loadStream rather than loadSound. Useful when one piece of UI drives both kinds of sound and has to hide the controls a stream does not support, such as sprite buttons.
isStream(id: string): boolean;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | The id to check. |
Returns
boolean: true for a loaded stream. false for a buffered sound and for an id that does not exist.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('click', '/audio/click.wav');
await soundHub.loadStream('episode-42', '/audio/episode-42.mp3');
soundHub.isStream('episode-42'); // true
soundHub.isStream('click'); // false
soundHub.isStream('nothing'); // false
// Only offer sprite controls where they can work
if (!soundHub.isStream('click')) {
renderSpriteButtons('click');
}
Good to know
- After
unloadSoundorremoveSounda stream id returnsfalse. - It never logs an error for an unknown id.
See also
loadStream: load a long file as a stream.getStreamElement: the media element behind a stream.hasSound: check whether an id is loaded at all.