Skip to main content

isStream

isStream(id: string): boolean;

Whether this id was loaded with loadStream rather than loadSound.

Useful when one piece of UI drives both kinds of sound and you need to hide the controls a stream does not support, such as sprite buttons.

ParameterTypeDescription
idstringThe sound id to check

Returns 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('laser', '/audio/laser.wav');
await soundHub.loadStream('episode-42', '/audio/episode-42.mp3');

soundHub.isStream('episode-42'); // true
soundHub.isStream('laser'); // false
soundHub.isStream('nothing'); // false

// Only offer sprite controls where they can actually work
if (!soundHub.isStream(id)) {
renderSpriteButtons(id);
}