Currently when I load my clips I call this:
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(audioFormat, audio, 0, size);
clip.stop();
clip.flush();
clip.close();
So that the Clip is loaded into memory and won’t lag before playing the first time I call for it. This works fine on Windows and Linux, but on Mac’s it makes little clicking sounds like it’s playing the beginning of each clip. Is there a better way to do this?
Also, can I reuse Clips? Right now the biggest thing making the allocations build up so that the GC gets called frequently is my use of Clips. I want to be able to hold on to a Clip and tell it to .start() again later or something so that I don’t have to create a new one.
To try this I take that first clip and call:
if (!clip.isOpen()) {
clip.open(audioFormat, audio, 0, size);
}
clip.start();
However this doesn’t seem to work. If this is possible, what do I need to do to reuse my Clips?