NOTE: The practical solution is with functions and objects java but the technique will be the same or very similar in any of the usual object-oriented languages.
If they could be named with the numbers for export
As to rename them, if it is to load them you do not need it, if you have the files in the same directory, you can load all the files dynamically:
File folder = new File("ruta/al/directorio/de/tus/sonidos");
for (File f : folder.listFiles()) {
// cargar en el array/list de sonidos
}
and then when loading them, referring to the index [i] would avoid writing the same code 100 times. Depending on the value of "i" one sound or another would be charged. Is it possible to do this?
Yes, in object-oriented languages it is possible to create an array or a collection of audio / sound type objects compatible with the files you have.
In java you can use the class Clip
, depending on what you want File
will also help you.
Either fine creating an array []
:
Clip[] sonidos = new Clip[numeroDeSonidos];
Or a ArrayList
(so you will not need to know the size beforehand as they are dynamic in size):
ArrayList<Clip> sonidos = new ArrayList<>();
In both cases, you can iterate through the Clips you can use a for-each:
for (Clip c : sonidos) {
c.loop(1); // hacer que suene 1 vez... OJO A QUE SE SOLAPARAN!
}
Or take an element for the position:
sonidos[posicion]; // array
sonidos.get(posicion)¡; // ArrayList