I have been experimenting with particles and such now couple days. Yesterday evening I decided to add some booms to my app but I could not get sound out. Example in test worked ok but my attempt to play a sound effect once was dead silent.
The problem turned out to be that I had to set volume for the AudioTrack. I guess the volume in AudioPlayer is not set otherwise.
Here is a simple example, modified from TestJmexAudio.
protected void simpleUpdate() {
audio.update();
if (timeToBoom && !sfx.isPlaying()) {
sfx.setWorldPosition(boomPos);
sfx.setEnabled(true);
sfx.setVolume(1f);
sfx.play();
}
// should I also add sfx.stop() ???
}
protected void simpleInitGame() {
audio = AudioSystem.getSystem();
audio.getEar().trackOrientation(cam);
audio.getEar().trackPosition(cam);
sfx = getSFX(Kaboom.class.getResource("firework_3.wav"), false);
}
private AudioTrack getSFX(URL resource, boolean loop) {
AudioTrack sound = AudioSystem.getSystem().createAudioTrack(resource, false);
sound.setType(TrackType.POSITIONAL);
sound.setRelative(false);
sound.setLooping(loop);
return sound;
}