Skip to main content

resume

Carry on a paused sound from the point where pause left it.

resume(id: string, skipDispatchEvent?: boolean): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of the sound or stream to resume.
skipDispatchEventbooleanfalseWhen true, no resumed 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 });
soundHub.pause('music');

// Later: continue from the saved position
soundHub.resume('music');

Try it​

Try it

Resume where you paused

Idle
Sound'tokyo-train'
Statestopped

Play, pause, then resume. The sound continues from the same point instead of restarting.

Code
Your clicks show up here as soundhub calls

Good to know​

  • Does nothing unless the sound is paused. A playing or stopped sound is left alone.
  • Dispatches SoundEventsEnum.RESUMED ('resumed') and not started. The volume, mute and fades are not applied again.
  • If you seek while paused, resume starts from the new position.
  • Works on streams from loadStream too. For an id that is not loaded, the error is logged, stored for getLastError and dispatched as an error event.

See also​

  • pause: pause a sound and keep its position.
  • resumeAllSounds: resume every paused sound.
  • play: start a sound that is stopped.