With Applet's sound stuff you have a delay each time a sound is played for the first time (they get moved into ram then).

With the sampled package it's a bit different - Clips are played instantly (because they are already in ram). However, the very first time you try to play a sound a mixer object (the default mixer) is created. Therefore you end up with a small delay, which was in your case big enough for not playing the sound at all.

You can test that easily. Play the sample wait a second, play it again, wait 2 seconds and exit... or make a little test application, which plays the sound if you click a button. You'll see that there won't be a delay the second time.

For games it doesn't really matter. You play lot's of sounds and most people don't even notice that the first sound effect was somewhat off.

However, if you really want to fix that... creating a mixer object by yourself should do the trick.

When I load sounds for my game, I'll create a Clip of the sound as I load it, and call what I need to get the Mixer created, and then just toss it away. Getting the mixer made seems to me to be part of the loading process, so I think that's a good time to do it.

hmm I'd guess that it's still open because you haven't played the Clip yet. For mine I just .flush() and .close() it after that first load. I think the only way it'll do that on its own is if you call .start() to let it run through and thus avoid the permanent open-ness... but you don't want it to play when you're loading it because you just want to make the mixer so it won't sound silly

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org