IndexOutOfBoundsException

Hello, i copied a very simple code from the website,https://processing.org/reference/libraries/sound/SoundFile.html but turns out the problem:IndexOutOfBoundsException
.I’ve checked that the file is in the data folder. I really do not know why, can somebody help? Thx

  
import processing.sound.*;
SoundFile file;

void setup() {
  size(640, 360);
  background(255);
    
  // Load a soundfile from the /data folder of the sketch and play it back
  file = new SoundFile(this, "sample.mp3");
  file.play();
}      

void draw() {
}

I tried your code and it works on my machine, P3.5.3 and Win 10 OS.

I suggest you try another mp3 file. In addition, if the file were not in the data folder, it will give you a NPE error and not an IndexOutOfBoundsException error.

Kf

2 Likes

Possibly relevant:

2 Likes

I had the same issue. According to the Processing Sound Library github readme “Some MP3 files with meta-information (especially where large amounts of data such as the album cover image is stored in the ID3 header) fail to load (see #32)”.

In short, nothing is wrong with the code. It’s the audio file.

2 Likes