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?

• Could you stream the tracks from the disk instead of loading them to the memory? Google for OggInputStream. Nov 3 '15 at 13:57
• Am I able to pause an OggInputStream without delay as I am with Clips? Nov 3 '15 at 23:06

When one track is done you start the next one and also start loading the track (in a background thread) to be played after that one and close() the Clip that just finished.