Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in setCurrentAudioTime #14

Open
MiteshDarda opened this issue Jul 23, 2024 · 1 comment
Open

Error in setCurrentAudioTime #14

MiteshDarda opened this issue Jul 23, 2024 · 1 comment
Assignees

Comments

@MiteshDarda
Copy link

MiteshDarda commented Jul 23, 2024

Describe the bug
setCurrentAudioTime is taking the indicator correctly to the given time,
but when i use togglePauseResume() it starts from the old time stamp,
i think setCurrentAudioTime it is not updating

To Reproduce Steps to reproduce the behavior:

  1. Play the recording let jump to any second expect 0
  2. Use the function recorderControls.setCurrentAudioTime(0);
  3. Then call the funciton recorderControls.togglePauseResume()
  4. See the error that time is not updated properly

Expected behavior
When i do togglePauseResume it should play from 0 seconds

** Screenshots**
Watch the video

** Package info **
2.0.2

** Additional context **

const restartPlayback = () => {
     recorderControls.setCurrentAudioTime(0);
     recorderControls.togglePauseResume()
}
@justinformentin
Copy link

justinformentin commented Jul 26, 2024

I had the same problem. Looks like the issue is here

const handleTimeUpdate = () => {

It seems that setting setCurrentAudioTime doesn't have an effect on anything because currentAudioTime gets immediately overwritten by audioRef.current.currentTime in the requestAnimationFrame loop.

We just need a way to change the audioRef.current.currentTime @YZarytskyi let me know your thoughts:

Keep setCurrentAudioTime and audioRef.current internal, and expose a a new function, something like

  const overrideCurrentAudioTime = (time: number): void => {
    if (!audioRef.current) return;
    audioRef.current.currentTime = time;
    setCurrentAudioTime(audioRef.current.currentTime);
  }

Where the audioRef.current.currentTime gets set so it plays from that time, and the currentAudioTime state gets set which is necessary to move the indicator if the track is paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants