Sound.stop() not returning 0 on sound.currentTime()

I think there is something wrong / buggy in p5 sound. When you hit stop it should return zero for currentTime(), unless I am misunderstanding the intended behavior. I’m trying to change the sound playing using an array, and constructors are plotting graphs off time values using sound.currentTime(). When the sound starts over, it’s obviously a big problem not to get 0 but to get the last time value of when the song was playing. Destroying the array of sounds, or recreating the sound variable itself does not do anything. sound.jump(0), also useless. The browser has the .currentTime() variable stuck in memory somewhere which needs to be expunged. Does anyone know a workaround?

Here is an example of stopping the song not giving zero. You would expect it to return the time value if using something like pause(), so I’m not understanding what’s wrong:

    sound.stop();
    console.log(sound.currentTime());
    sound.play();
    console.log(sound.currentTime());

something I tried that seems to work, but I’m not sure if this sketchy to attempt (why I’m posting this):

  sound.stop();
  sound._lastPos=0;
  console.log(sound.currentTime());
  sound.play();
  console.log(sound.currentTime());

this gives you zero, which is correct for my application. Any advice appreciated.

1 Like

This definitely looks like at least an idiosyncrasy in the implementation of SoundFile. I can’t see a reason in the code why it shouldn’t set _lastPos to 0 when stop() is called. You can report an issue on GitHub.

1 Like

Thanks for the help. This may have been reported already. Maybe I will report it again, but I think it might get solved in the next release. For now I’ll use the _lastPos. Now, if I can only get video.play().time(x) to work…