Skip to main content

getLoop

Check whether a sound is set to loop, for example to show the state of a loop button.

getLoop(id: string): boolean;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of the sound or stream.

Returns​

boolean: true when the sound loops. For an id that is not loaded you get false, without an error.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');

soundHub.getLoop('music'); // false

soundHub.setLoop('music', true);
soundHub.getLoop('music'); // true

Good to know​

  • It reads the loop value in the sound's play options, so it reflects setLoop and any play() call with loop. It says nothing about maxLoops or how many passes are left.
  • A new sound starts with the loopSounds value from the config, false by default.
  • For a stream from loadStream it returns the media element's loop.

See also​