Skip to content

Commit

Permalink
fix(921): additional useEffect for resetting the time
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejsikuade authored and lhaggar committed Sep 17, 2024
1 parent 6d9ae8a commit 44b7fd0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/audio-player-composable/audio-player-composable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@ export const AudioPlayerComposable = ({
currentTimeRef.current = currentTime;
});

useEffect(() => {
setCurrentTime(0);
setDisplayDuration(0);
}, [src]);

useEffect(() => {
// On render onTimeUpdate will be fired and initialTime will be set as a value for currentTime state.
// I can't set this one to the setCurrentTime state directly as the audioElement time
// will still be 0, currentTime will be overridden to 0 and the audio will start from 0

if (audioRef && audioRef.current && duration) {
audioRef.current.currentTime = initialTime;
}
setCurrentTime(0);
setDisplayDuration(0);
}, []);
}, [duration, initialTime]);

const {
audioEvents,
Expand Down

0 comments on commit 44b7fd0

Please sign in to comment.