I am currently developing a game with Java, with a soundtrack consisting of ten tracks in .ogg format, 1-2 MB in size each. To be able to switch between these tracks quickly and easily in the game, before the game starts, I load all of them into memory by creating ten Clip
classes. Unfortunately, but understandably, pre-loading these tracks increases the application's CPU usage from about 61 MB to 340 MB.
Since I'm only ever playing one track at a time, I could make it so that only one Clip
is ever in memory, and is destroyed when the track needs to change. This means, though, that I'll have to hang the game up on loading the Clip
when this happens, or do this on a different thread during a few seconds of undesirable silence.
Is there a smarter, more conventional way to handle large BGM files, or do I just have to pick my poison?