p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

currentTime resets to 0

Open Xendergo opened this issue 8 years ago • 3 comments

When I play the file, currentTime() increases as normal, but when I call pause() it resets to 0, but when I play it again, it goes back to whatever time you called pause at.

Xendergo avatar Mar 09 '18 01:03 Xendergo

I've noticed this too, but I can't tell if it is intended or not. My guess is that maybe it is p5.sound's current way of eliminating DC in the signal when paused.

What I have done to circumvent it in a sound file player where I want the playhead to maintain the position point when paused, is to store a snapshot of currentTime() into a variable right before calling pause(), and using that variable to draw the playhead in the case that the soundfile is paused.

//inside event listener
if (!mySound.isPlaying()) {
   mySound.play();
} else {
   pausedSoundTimePoint = mySound.currentTime(); // <- snapshot currentTime() before pausing
   mySound.pause();
} 

then when drawing the playhead, toggle between using pausedSoundTimePoint and currentTime() based on whether or not the soundfile is playing...

//inside draw function
if (!mySound.isPlaying()) { 
   soundCurrentTime = pausedSoundTimePoint;
} else {
   soundCurrentTime = mySound.currentTime();
}
line(soundCurrentTime*width/soundDuration, 0, soundCurrentTime*width/grooveDuration, height);

datramt avatar May 26 '18 19:05 datramt

VM4 315bf5aa-9268-4520-8629-6fd178e08add:75 Uncaught TypeError: Cannot read property 'length' of undefined
    at RingBuffer.push (VM4 315bf5aa-9268-4520-8629-6fd178e08add:75)
    at AudioWorkletProcessor.process (VM4 315bf5aa-9268-4520-8629-6fd178e08add:170)

It seems there's a bug in p5sound.

I get the above in the console when trying to getCurrentTime(). I only ever get zero back

Here's my example: https://editor.p5js.org/everythingability/sketches/cp7Csqzid

everythingability avatar Sep 09 '20 11:09 everythingability

Fixed by #542, but not released I think - current release of p5 doesn't have this fix.

rbtcollins avatar Jan 02 '21 08:01 rbtcollins