jump() function
See original GitHub issueHi, I encountered several issues with the jump function. I don’t know how to format the message nicely as in issue #370, sorry. So:
- Found a bug
- Sound
- Desktop/Laptop
Details about the bug:
- p5.js version: v0.8.0 April 08, 2019
- Web browser and version: Firefox 67.0.4 (64 bits)
- Operating System: Windows 10
- Steps to reproduce this: 1/ Using
function jumpSong() {
let songLength = song.duration();
song.jump(songLength / 2); // jump to the middle of the song
}
or
function jumpSong() {
song.jump(20); // jumps forward with 20 secondes
}
1/ New instances of the song are created while song is still playing + 2/ In the console, the song.stop() doesn’t work anymore + 3/ The ‘play/pause’ button is working, but once I click on the ‘jump’ button, the ‘play-pause’ isn’t working anymore, I can click on it, but it won’t pause the song.
I also experienced this:
function jumpSong() {
let songLength = song.duration();
let randomTime = random(songLength);
console.log(randomTime);
song.jump(randomTime); // jumps to a random moment in the song
}
1/ If I first click the ‘play’ button, and then ‘jump’ button, a new instance of the song adds itself the one playing, but 2/ If I only click on ‘jump’ button, I have 2 times a normal jump, and on the 3rd click a new instance adding itself to the one playing.
Thanks for that wonderful library, very excited to learn it! 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top GitHub Comments
For the time being (as a workaround) this works for me, both in Firefox and Chrome: after the
sound.jump();
function is called usesetTimeout(function(){ Object.assign(sound, {_playing: true}); }, 100);
In Safari I still get
InvalidStateError: The object is in an invalid state.
To get it working in Safari (and Firefox and Chrome) I have the following workaround before thesound.jump();
function:The first time the
jump()
function is called the sound object has value_playing
set tofalse
, but if you run thejump()
function again, value_playing
is set totrue
. It toggles between these two values.Even
Object.assign(sound, {_playing: true})
orObject.assign(sound, {_playing: NaN})
will only work on every second time…The problem seems to be in this small code on line 3161 from p5.sound.js v0.3.11
If I remove this, the problem seems to be solved. I don’t know why it is set alternately and not every single time the
jump()
function is activated…