Skip to main content

stop

Stop a sound and forget its position. Unlike pause, the next play starts from the beginning (or from the startTime in its play options).

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

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of the sound, instance or stream to stop.
skipDispatchEventbooleanfalseWhen true, no stopped 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 });

// Stop and reset the position
soundHub.stop('music');

// Playing again starts from the beginning
soundHub.play('music');

Try it​

Try it

Stop and start over

Idle
Sound'tokyo-train'
Statestopped

After a stop, Play starts from the beginning. Use pause to keep your place.

Code
Your clicks show up here as soundhub calls

Good to know​

  • Cancels any running fade and any pending fadeOutBeforeEndDuration fade, and stops progress tracking.
  • Event listeners added with a filter on this exact instance id are removed.
  • Dispatches SoundEventsEnum.STOPPED ('stopped'), also when the sound was already stopped.
  • An id that is not loaded is ignored quietly: no error is logged or dispatched.
  • Works on streams from loadStream too. A stream goes back to its start offset.
  • On a variation name from createVariations it stops every take and every instance of them that is not already stopped. Added in 6.5.0

See also​

  • pause: halt a sound and keep its position.
  • stopAllSounds: stop everything at once.
  • fadeOut: fade a sound out and stop it afterwards.
  • isStopped: check whether a sound is stopped.