isStopped
Check whether a sound is stopped. A sound is stopped before it first plays, after stop, and after it reaches its end.
isStopped(id: string): boolean;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound, stream or overlapping instance. |
Returns
boolean: true when the sound is stopped, and also for an id that is not loaded. false when it is playing or paused.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');
soundHub.isStopped('rain'); // true, not started yet
soundHub.play('rain', { loop: true });
soundHub.isStopped('rain'); // false
soundHub.stop('rain');
soundHub.isStopped('rain'); // true
Try it
Ask a sound where it is
IdleisPlaying()false
isPaused()false
isStopped()true
Exactly one of the three is true at any moment. The values are read five times a second.
Code
Your clicks show up here as soundhub calls
Good to know
- An unknown id returns
true, unlikeisPlayingandisPaused, which returnfalse. The error is still logged, stored forgetLastErrorand dispatched as anerrorevent. - With
overlap, the base id stays stopped while its instances (click:1,click:2) play. - A sound that reached its end is stopped too, and its position is back at the start.
See also
stop: stop a sound.isPlaying: check for a playing sound.isPaused: check for a paused sound.getSoundState: state, time and progress in one object.