Skip to content

Commit

Permalink
Feat: allow user to update peaks and/or duration with setOptions (#3982)
Browse files Browse the repository at this point in the history
  • Loading branch information
botoxparty authored Jan 6, 2025
1 parent 0ffead9 commit ef0ba84
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/wavesurfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ 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)
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)

if (options.audioRate) {
Expand Down

0 comments on commit ef0ba84

Please sign in to comment.