Skip to content

Commit

Permalink
Fix: set position to the latest sample
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Aug 11, 2024
1 parent da42501 commit cac58a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/plugins/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOptions> {
// Render the waveform
if (this.wavesurfer) {
const totalDuration = (this.dataWindow?.length ?? 0) / FPS
const position = sampleIdx / this.dataWindow.length

this.wavesurfer
.load(
Expand All @@ -174,10 +175,12 @@ class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOptions> {
)
.then(() => {
if (this.wavesurfer && this.options.continuousWaveform) {
this.wavesurfer.setTime(this.getDuration() / 1000)
this.wavesurfer.seekTo(position)

if (!this.wavesurfer.options.minPxPerSec) {
this.wavesurfer.options.minPxPerSec = this.wavesurfer.getWidth() / this.wavesurfer.getDuration()
this.wavesurfer.setOptions({
minPxPerSec: this.wavesurfer.getWidth() / this.wavesurfer.getDuration(),
})
}
}
})
Expand Down

0 comments on commit cac58a4

Please sign in to comment.