isPaused
Check whether a sound is paused. A paused sound keeps its position, and resume carries on from there.
isPaused(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 paused. false when it is playing, stopped, or the id is not loaded.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music');
soundHub.pause('music');
soundHub.isPaused('music'); // true
soundHub.resume('music');
soundHub.isPaused('music'); // false
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
- A sound played with
durationandpauseAtDurationReachedends up paused rather than stopped when the duration runs out. stopon a paused sound makes it stopped, and its position goes back to the start.- For an id that is not loaded, the answer is
false, but the error is also logged, stored forgetLastErrorand dispatched as anerrorevent.
See also
pause: pause a sound.resume: carry on from the paused position.isPlaying: check for a playing sound.getSoundState: state, time and progress in one object.