Playing randomly triggered audio files

Hello JUCE fam,

I’ve got a set of audio files that are randomly triggered to be played by my JUCE app.

When an audio file is triggered to play, I create an AudioFormatReaderSource to read from the file and I add it as an input to my application’s AudioMixerSource which plays audio to the main outputs.

When an audio file is finished playing, I want to remove its associated AudioFormatReaderSource from the AudioMixerSource.

Is there an easy way to removeInputSource() from my AudioMixerSource when a file is done playing?

Also, am I approaching this problem correctly by having a AudioFormatReaderSource per audio file that gets triggered?
(I know it would be more efficient to load these audio files into memory if I knew a certain subset of them would be used, and then read them from there.)

Thanks for the help.

You might want to make your own AudioSource subclass that holds the AudioFormatReaderSource and can make some kind of a callback once it is finished. (In a pinch it might maybe even just hold a pointer to your AudioMixer, so it could call the remove method of the mixer directly…)