Looping
Looping is new in 2.0. It works in self mode only: an external-mode player ignores all of it, because its controller owns playback.
Loop the whole track
Section titled “Loop the whole track”<div data-waveform-player data-url="/audio/drum-loop.mp3" data-loop="true" data-show-loop="true"></div>new WaveformPlayer('#player', { url: '/audio/drum-loop.mp3', loop: true, showLoop: true });loop uses the <audio> element’s own loop, so the wrap is seamless.
ended / onEnd don’t fire on it; the wrap is a seek to 0, so seek (and
timeupdate) fire instead.
showLoop adds a loop toggle to the meta row: a real <button> with
aria-pressed, named by loopLabel (default 'Loop'). Pressing it turns
looping off when any loop (track or section) is on, and whole-track looping on
otherwise. It needs showInfo (the meta row).
Loop a section
Section titled “Loop a section”player.setLoop(32, 48); // loop 0:32–0:48player.loopMarker(1); // loop marker 1 to the next marker (or the end)player.clearLoop(); // stop the section loopsetLoop(start, end)loops a section in seconds. Once the playhead reachesendit jumps back tostart; if it is outside the section it moves tostart. Anendpast the track (orInfinity) loops to the end. Invalid bounds (end <= start, non-numbers) are ignored.loopMarker(index)loops from a marker (its position inmarkers) to the next marker in time — handy for chapters, verses or stems.clearLoop()stops the section; whole-track looping, if on, carries on.
While a section is set it wins over whole-track looping, and ended never fires
inside it. A section is per-track: a new track clears it.
Toggle from code
Section titled “Toggle from code”player.toggleLoop(); // flip, like the button; returns the new stateplayer.toggleLoop(true); // whole-track looping onplayer.toggleLoop(false); // every loop off, section includedEvents
Section titled “Events”Every change — toggleLoop(), setLoop(), clearLoop(), the button, a new
track dropping a section — fires loop on the instance and a bubbling
waveformplayer:loop on the container:
document.addEventListener('waveformplayer:loop', (e) => { const { loop, start, end } = e.detail; // start/end are null without a section console.log(loop ? 'looping' : 'not looping', start, end);});React, Vue and Svelte expose it as onLoop / @loop / onloop. See
Events.