Skip to main content

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​

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

Try it

Ask a sound where it is

Idle
isPlaying()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, unlike isPlaying and isPaused, which return false. The error is still logged, stored for getLastError and dispatched as an error event.
  • 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​