Skip to content

Commit

Permalink
Fix: [Timeline] render on initial redraw (#3327)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Nov 8, 2023
1 parent fbb1bae commit 7509ea3
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/plugins/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,10 @@ class TimelinePlugin extends BasePlugin<TimelinePluginEvents, TimelinePluginOpti
container.appendChild(this.timelineWrapper)
}

if (this.options.duration) {
this.initTimeline(this.options.duration)
} else {
this.subscriptions.push(
this.wavesurfer.on('redraw', () => {
this.initTimeline(this.wavesurfer?.getDuration() || 0)
}),
)
this.subscriptions.push(this.wavesurfer.on('redraw', () => this.initTimeline()))

if (this.wavesurfer?.getDuration() || this.options.duration) {
this.initTimeline()
}
}

Expand Down Expand Up @@ -146,7 +142,8 @@ class TimelinePlugin extends BasePlugin<TimelinePluginEvents, TimelinePluginOpti
return 2
}

private initTimeline(duration: number) {
private initTimeline() {
const duration = this.wavesurfer?.getDuration() ?? this.options.duration ?? 0
const pxPerSec = this.timelineWrapper.scrollWidth / duration
const timeInterval = this.options.timeInterval ?? this.defaultTimeInterval(pxPerSec)
const primaryLabelInterval = this.options.primaryLabelInterval ?? this.defaultPrimaryLabelInterval(pxPerSec)
Expand Down

0 comments on commit 7509ea3

Please sign in to comment.