Load sounds with an array of SoundFile

I try to load multiple sounds with an array of SoundFile, but I keep getting a Error: Soundfile doesn't exist. Pleae check path when I try to initalize the array.

Here’s my function (I want it to return a SoundFile array in order to give it to an object):

SoundFile[] loadSoundFiles(String path, String[] fileList) {
  SoundFile[] soundFile = new SoundFile[fileList.length]; // initialize the array
  for (int i=0; i<fileList.length; i++) {
    soundFile[i] = new SoundFile (this, path + "/" + fileList[i]);
  }
  return soundFile;
}

The error seems to be on this line:

SoundFile[] soundFile = new SoundFile[fileList.length]

fileList contains the file names, for example: {"file0.wave", "file2.wav}

For me it works if called like this:

void setup() {
  sounds = loadSoundFiles("../data", new String[] {"vibraphon.aiff"});
  printArray(sounds);
  sounds[0].play();
}      

The default path seems to be data/ so I need to specify ../data to go one level up, then back into data, then find the files there. If I specify data instead of ../data, it’s probably looking for data/data/vibraphon.aiff which returns the error you mention.

Thank you for the answer! Actually my code was working, the error was because I made a typo on the “path” variable… And I didn’t need to specify the data folder.

Le mer. 15 août 2018 à 18:29, aBe processingfoundation1@discoursemail.com a écrit :