TL;DR: How can I access the audio instances created in the callback of createAdio?
I have the following code in my p5 sketch
// in preload
sound_a = createAudio('sound_a.mp3');
// in setup
sound_a.loop();
sound_a.volume(0.2);
sound_a.play();
This does what I want it to do. However, in my current circumstances, I have multiple audio files for which I wanted to call the same functions. I would want to use a callback to apply the loop
, volume
and play
. My intended behavior is something like this:
// in preload - this would just be a loop
sound_a = createAudio('sound_a.mp3', audio_callback);
sound_b = createAudio('sound_b.mp3', audio_callback);
.....
sound_z = createAudio('sound_z.mp3', audio_callback);
function audio_callback(audio) {
audio.loop();
audio.volume(0.2);
audio.play();
}
However, the callback is not passed any arguments (i.e., console.log(audio)
returns undefined and audio.loop()
throws the expected errors.). How can I access the audio created in the callback?