pause
Pause a playing sound. The position is kept, so resume carries on from the same point. Use stop instead when you want the next play to start from the top.
pause(id: string, skipDispatchEvent?: boolean): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream to pause. |
skipDispatchEvent | boolean | false | When true, no paused event is dispatched. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
// Pause, the position is kept
soundHub.pause('music');
// Later: carry on from the same point
soundHub.resume('music');
Try it
Pause and pick up again
IdleSound'tokyo-train'
Statestopped
Pause keeps the playback position. Resume carries on from exactly that point.
Code
Your clicks show up here as soundhub calls
Good to know
- Does nothing when the sound is not playing or is already paused. No event is dispatched then.
- A pending
fadeOutBeforeEndDurationfade is cancelled, and progress tracking stops until the sound plays again. - Dispatches
SoundEventsEnum.PAUSED('paused'). - Works on streams from
loadStreamtoo. For an id that is not loaded, the error is logged, stored forgetLastErrorand dispatched as anerrorevent.
See also
resume: carry on from where the sound was paused.stop: halt the sound and forget its position.pauseAllSounds: pause everything at once.isPaused: check whether a sound is paused.