Skip to content

Commit

Permalink
fix: #3707
Browse files Browse the repository at this point in the history
  • Loading branch information
shellRaining authored Sep 2, 2024
1 parent 5f32d82 commit 1a0cc9d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/wavesurfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,10 @@ class WaveSurfer extends Player<WaveSurferEvents> {

/** Get the duration of the audio in seconds */
public getDuration(): number {
let duration = super.getDuration() || 0
// Fall back to the decoded data duration if the media duration is incorrect
if ((duration === 0 || duration === Infinity) && this.decodedData) {
duration = this.decodedData.duration
}
return duration
if (this.decodedData) return this.decodedData.duration
// Fall back to the audio data duration if the audio not decoded
// if super.getDuration == NAN, which means it's impossible to get the duration, should wait until onloadedmetadata trigger
return super.getDuration() || 0
}

/** Toggle if the waveform should react to clicks */
Expand Down

0 comments on commit 1a0cc9d

Please sign in to comment.