Skip to content

Commit

Permalink
Allow user to update peaks and/or duration with setOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
botoxparty committed Jan 3, 2025
1 parent 0ffead9 commit 48ecb32
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/wavesurfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,25 @@ class WaveSurfer extends Player<WaveSurferEvents> {
/** Set new wavesurfer options and re-render it */
public setOptions(options: Partial<WaveSurferOptions>) {
this.options = Object.assign({}, this.options, options)
this.renderer.setOptions(this.options)

if (options.audioRate) {
this.setPlaybackRate(options.audioRate)
}
if (options.mediaControls != null) {
this.getMediaElement().controls = options.mediaControls
}
if (options.duration && !options.peaks) {
this.decodedData = Decoder.createBuffer(this.exportPeaks(), options.duration)
}
if (options.peaks && options.duration) {
// Create new decoded data buffer from peaks and duration
this.decodedData = Decoder.createBuffer(
options.peaks,
options.duration
);
}

this.renderer.setOptions(this.options)
}

/** Register a wavesurfer.js plugin */
Expand Down

0 comments on commit 48ecb32

Please sign in to comment.