Hello folks.
I am having a hard time with sound effects on my TinyGame entry (Zombie Defense ) .
I tried using EasyOgg from kevGlass, but I was having bad sound glitches … then I read somewhere it was supposed to be used to play background music , not sound effects .
Then I switched back to my old WAV playing code . It seems to work well, except that my final jar got much much bigger than when I used ogg (from 700K to 2.5 MB), for obvious reasons , and additionally it seems to create a major leak .
my code for playing a wave is the following :
byte[] bytes ;
Clip clip;
public SSound (String s)
{
bytes = loadBytesFromStream(Thread.currentThread().getContextClassLoader().getResourceAsStream(s));
}
public void play()
{
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
AudioInputStream ain;
try {
ain = AudioSystem.getAudioInputStream(is);
DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat());
clip = (Clip)AudioSystem.getLine(info);
clip.open(ain);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
I know there are alternatives using 3d sounds, but I would have to sign my jar, which is neither desirable for me nor for the TinyGame Comp.
So is there a good and memory friendly way to play sound effects ?
Thank you in advance .