Skip to main content

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​

ParameterTypeDefaultDescription
idstringrequiredThe 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​

See also​