p5.js-sound
p5.js-sound copied to clipboard
.play() throws error - Cannot read property 'length' of undefined - RingBuffer.push()
/** [p5.sound] Version: 0.3.12 - 2020-01-06 */
A new problem arose yesterday or the day before. I've been using the same code for a couple of weeks with no problems.
If you call .play() after .loadSound(), the following error/stack is thrown:
730ccbef-3078-419b-80e3-0b3b03baca05:75 Uncaught TypeError: Cannot read property 'length' of undefined at RingBuffer.push (730ccbef-3078-419b-80e3-0b3b03baca05:75) at AudioWorkletProcessor.process (730ccbef-3078-419b-80e3-0b3b03baca05:170) push @ 730ccbef-3078-419b-80e3-0b3b03baca05:75 process @ 730ccbef-3078-419b-80e3-0b3b03baca05:170
This can be observed on the official p5js.org website here: https://p5js.org/reference/#/p5.EQ
Click on the 'lows' button to throw the error
I've tested this on multiple browsers with the same error. Currently I'm testing on Chrome (Version 84.0.4147.105 (Official Build) (64-bit)).
I've never submitted before, so I don't know if I'm reporting this properly, or if this is already known/tracked.
I've been able to use the developer portable version of Firefox (v80) to get around this issue. The error is still thrown, but the methods work properly on that version.
I am having exactly the same problem - this is on code which was working perfectly before, but now suddenly throws an error as soon as I attempt to play any sound file.
I have written a simple test case which will cause the error to display:
const audioFile = '[insert path to audio file here]';
let audioStream;
let playing = false;
window.setup = () => {
createCanvas(640, 480);
background(0,128,0)
audioStream = loadSound(audioFile, function () {
console.log('loaded', audioFile);
});
console.log('loading', audioFile);
};
window.draw = () => {
if (!playing && audioStream.isLoaded()) {
playing = true;
console.log('play');
audioStream.play();
console.log('playing');
}
};
This PR fixes the RingBuffer length error and the currentTime() issue https://github.com/processing/p5.js-sound/pull/542
how do you get this fix for the ringbuffer.length()? also having this appear in my projects.
how do you get this fix for the ringbuffer.length()? also having this appear in my projects.
I guess with the next release of the p5 sound library.
I rolled back to 0.3.0 p5 sound until they fix it.
I have this issue when running version 1.1.9. Anyone else?
Yes, I am still having this error. Here are some reasons...
Firstly, last time I looked, the fix for this didn't yet appear to have been merged into the latest release (which came out about 6 months ago). I've not checked again for the last few weeks, but obviously without the fix in the release, the release won't be fixed!
However I went into the code and manually applied the fix to my own version. It meant that the error messages stopped, but my app still did not work. On checking the code, all that it does is short-circuit the error messages. It does not address whatever it is that is causing the error in the first place.
I'm still having this issue, as well as cracking sounds in version 1.3.1 as well! Hope for a fix soon!
I dont know why this issue is closed because it is not fixed.
I got this error too, any news?
This issue should not be closed, as the issue still occurs.
Agreed, this is very much a live issue. Sadly I had to abandon my p5js project because of this issue.
Same here, basically stuck using old versions of p5 sound.
Also still having this error. NFTs on hicetnunc won't run on iPhone safari because of this.
Confirming, having the same issue, happening when simply using .loop() or .jump()
I have the same problem
Same here, basically stuck using old versions of p5 sound. What version are you using?
I switched to Howler.js for soundfile playback. Can recommend! Great API, great performance.
Damn, that gave me hope of finally fixing my scripts... sadly seems that Howler.js is only for playing sounds, doesn't have methods for fetching eq & spectrum data.
Does anyone know if there are actually any maintainers for p5.sound? This issue has been present for 9 months now, and no input from anyone about getting it fixed or even re-opened.
There is another thread here with some info (potentially?): https://github.com/processing/p5.js-sound/issues/494
Looks like the issue was resolved there with updating chrome - but this can't be resolved with chrome updates.
@theantonius I'm still seeing this issue in the latest dev build of Chrome.
@therewasaguy Please re-open, this is still an issue according to multiple reports above.
We need to properly release a new version of the library that includes the fix. I think this is how to do it, and I'll try to do that right now!
I'm very sorry that it's taken so long to release a new version. I've been a terrible maintainer and I feel terrible about that. I would be happy to make space for others, please reach out if you're interested.
I'll leave this open with https://github.com/processing/p5.js/pull/5266
@therewasaguy I'm not sure that merging the "fix" will fix things - see my comment here: https://github.com/processing/p5.js-sound/issues/506#issuecomment-756658958
I wrote a test case which highlights the error: https://github.com/processing/p5.js-sound/issues/506#issuecomment-672873135
thanks for the test case, @dansumption !
I took a quick look. If the test case was working before and now it isn't, that sounds like a regression / bug! But this might be a different / smaller issue because the test case assigns the result of loadSound
to a variable in setup()
and that approach isn't meant to work outside of preload()
.
It seems to work if we instead assign within preload
like this
window.preload = () => {
audioStream = loadSound(audioFile, function () {
console.log('loaded', audioFile);
});
};
or from the callback like this
window.setup = () => {
createCanvas(640, 480);
background(0,128,0)
loadSound(audioFile, function (gotFile) {
audioStream = gotFile;
console.log('loaded', audioFile);
});
console.log('loading', audioFile);
};
The documentation isn't clear on this, I see how it's confusing! We should create a second example, similar to the "outside of preload" example for loadJSON on this page - would anyone like to take that on?
Ah, thanks for that @therewasaguy !
This seems to work, although the code I left in a very messy state about a year ago still isn't working (my problem being that I'm not getting regular samples back from the audio once playing). This may well be something I've messed up - really need to re-familiarise myself with the project - but I do seem to recall getting it to a similar working state before, and still not able to get samples from the sound object.
I will see what more I can figure out, when I have a moment. Hopefully all fixed, but... possibly not.