# Error when playing SoundFile

**URL:** https://discourse.processing.org/t/error-when-playing-soundfile/23011
**Category:** Libraries
**Created:** [August 3, 2020, 1:33pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011 "2020-08-03T13:33:31Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)
#### Post date: [August 3, 2020, 1:33pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/1 "2020-08-03T13:33:31Z")

</div>

I have a p5js application which loads and plays a sound file. It was worked fine for a very long time, but suddenly it’s started throwing errors when I try to play the file.

I’ve stripped the code down to its basics, as well as trying it with different sound files, formats, browsers etc, but it breaks in all of them.

As soon as I call `audioStream.play()` I get the following error:

```auto
Uncaught TypeError: Cannot read property 'length' of undefined
    at RingBuffer.push (a95166f8-a660-483a-99b5-aafd118d4566:75)
    at AudioWorkletProcessor.process (a95166f8-a660-483a-99b5-aafd118d4566:170)

```

I’m speculating, due to the undefined error, that something may be trying to access the audio stream before it is fully instantiated, but after it’s loaded.

The error happens outside the flow of my program, I’m guessing in a timeout or something, so I can’t debug it from a point in my code. However, If I use:

```auto
console.log('play');
audioStream.play();
console.log('playing');

```

Then the error occurs between the two log statements, so it’s something that’s triggered by calling `play()` on the p5 `SoundFile` object.

Here is my code, stripped down as much as possible, which replicates the problem:

```auto

const audioFile = '../audio/Track.wav';
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');
  }
};

```

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 3, 2020, 3:03pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/2 "2020-08-03T15:03:22Z")

</div>

I too am at a loss for what’s going on. This code was working great for the last week and all of a sudden started receiving this error as well.

I’ve changed versions of p5/p5Sound and still no luck.

It’s happening cross browser as well and can’t even trace the stack properly.

I’ll post more if I find anything else.

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 3, 2020, 3:23pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/3 "2020-08-03T15:23:11Z")

</div>

audioTrack.currentTime(); always seems to be returning 0 for me now(Add that to the list of strange things that just started happening).

---

<div class="post-metadata">

### Author: ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)
#### Post date: [August 3, 2020, 3:26pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/4 "2020-08-03T15:26:50Z")

</div>

Thanks @Brewhog! Sorry to hear that you have this problem too, but very glad to learn that I am not alone. I thought this must be something I’d screwed up in my environment, but if it suddenly stopped working for you as well then it sounds like something broke elsewhere.

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 4, 2020, 3:20pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/5 "2020-08-04T15:20:59Z")

</div>

There is a problem with the library. Upon further investigation, this error is occurring on the [p5js.org](http://p5js.org) site examples as well. Go here to see what I’m talking about:  
[https://p5js.org/reference/#/p5.EQ](https://p5js.org/reference/#/p5.EQ)

Click the ‘lows’ button and open the developer console. The same RingBuffer.push() error is thrown.

Not sure how to report a bug, or confirm if this bug already exists.

---

<div class="post-metadata">

### Author: ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)
#### Post date: [August 4, 2020, 4:37pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/6 "2020-08-04T16:37:52Z")

</div>

Thanks for confirming. God, I spent hours pulling my code apart trying to figure out what I’d broken 🤣

I’m very very interested to know what it could be that has broken everyhing like this, without requiring an update of the p5js or p5 sound library themselves or, as far as I’m aware, any dependencies.

Know if there is any way of escalating this? Do the folks who contribute to p5 sound hang out on here? I’ve got a video to make for a DJ and the deadline is creeping closer. I would be glad to try and figure it out myself and submit a fix, but I think this one is beyond my abilities.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 4, 2020, 4:43pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/7 "2020-08-04T16:43:20Z")

</div>

> **[processing/p5.js-sound](https://github.com/processing/p5.js-sound/issues)**
>
> p5.sound brings the Processing approach to Web Audio and p5.js. Demos: - processing/p5.js-sound

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 4, 2020, 4:52pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/8 "2020-08-04T16:52:09Z")

</div>

Thanks. I’ll submit something shortly.

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 4, 2020, 4:52pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/9 "2020-08-04T16:52:44Z")

</div>

I’m going to try this on an older version of a browser and of the library. If it works fine, you might want to use that for your DJ.

If they’re willing to work with a slightly older browser, it might just work.

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 4, 2020, 4:58pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/10 "2020-08-04T16:58:39Z")

</div>

BTW, the portable firefox developer edition (v80) appears to work for me. However, there are still errors thrown.

Most important part is that all features seem to be functional (Although noisy with the errors).

[https://portableapps.com/downloading/?a=FirefoxPortableDeveloper&n=Mozilla%20Firefox%20Developer%20Edition,%20Portable&s=s&p=&d=pa&f=FirefoxPortableDeveloper\_80.0\_Beta\_1\_English.paf.exe](https://portableapps.com/downloading/?a=FirefoxPortableDeveloper&n=Mozilla%20Firefox%20Developer%20Edition,%20Portable&s=s&p=&d=pa&f=FirefoxPortableDeveloper_80.0_Beta_1_English.paf.exe)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [August 4, 2020, 5:07pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/11 "2020-08-04T17:07:13Z")

</div>

Another link to grab Firefox Developer Beta: 🦊

> **[Download the Firefox Browser in English (US) and more than 90 other languages](https://www.mozilla.org/en-US/firefox/all/#product-desktop-developer)**
>
> Everyone deserves access to the internet — your language should never be a barrier. That’s why — with the help of dedicated volunteers around the world — we make the Firefox Browser available in more than 90 languages.

---

<div class="post-metadata">

### Author: ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)
#### Post date: [August 4, 2020, 5:24pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/12 "2020-08-04T17:24:37Z")

</div>

Yeah, swapping browsers is no problem. Let me know if you find a workaround.

---

<div class="post-metadata">

### Author: ![Brewhog](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@Brewhog](https://discourse.processing.org/u/Brewhog)
#### Post date: [August 4, 2020, 6:16pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/13 "2020-08-04T18:16:05Z")

</div>

Added two bugs to the P5 Sound project GitHub project:

> <https://github.com/processing/p5.js-sound/issues/506>
>
> /\*\* \[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...

> <https://github.com/processing/p5.js-sound/issues/507>
>
> /\*\* \[p5.sound\] Version: 0.3.12 - 2020-01-06 \*/
> This might be related to the following issue (As it showed up in my code...

---

<div class="post-metadata">

### Author: ![egg\_yolk](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@egg\_yolk](https://discourse.processing.org/u/egg_yolk)
#### Post date: [March 6, 2021, 1:53pm UTC](https://discourse.processing.org/t/error-when-playing-soundfile/23011/14 "2021-03-06T13:53:38Z")

</div>

Is there a hotfix around for the RingBuffer.push() bug, or at least a way to stop the error from going into the console?
