Skip to content

Commit d9266af

Browse files
fix(UNT-T28235): sometime return negative song duration
1 parent 09c6449 commit d9266af

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/components/Waveform/Waveform.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
115115
durationType: DurationType.max,
116116
});
117117
if (!isNil(duration)) {
118-
setSongDuration(duration);
118+
const audioDuration = Number(duration);
119+
setSongDuration(audioDuration > 0 ? audioDuration : 0);
120+
return Promise.resolve(audioDuration);
119121
} else {
120122
return Promise.reject(
121123
new Error(`Could not get duration for path: ${path}`)
@@ -130,7 +132,10 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
130132
try {
131133
const prepare = await preparePlayerForPath();
132134
if (prepare) {
133-
await getAudioDuration();
135+
const duration = await getAudioDuration();
136+
if (duration < 0) {
137+
await getAudioDuration();
138+
}
134139
}
135140
} catch (err) {
136141
console.error(err);
@@ -413,7 +418,13 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
413418

414419
const tracePlaybackValue = onCurrentDuration(data => {
415420
if (data.playerKey === `PlayerFor${path}`) {
416-
setCurrentProgress(data.currentDuration);
421+
const currentAudioDuration = Number(data.currentDuration);
422+
423+
if (!isNaN(currentAudioDuration)) {
424+
setCurrentProgress(currentAudioDuration);
425+
} else {
426+
setCurrentProgress(0);
427+
}
417428
}
418429
});
419430

0 commit comments

Comments
 (0)