When jumping, a sound is played. Sometimes the sounds have to overlap (like if I jump up some stairs). However, I haven’t been able to go past this problem. My code makes it so both sounds are stopped when they overlap. The result is complete silence as I’m jumping.
I don’t care whether the solution will make sounds play simultaneously or stop the previous sounds, I just want the sounds to not be stopped.
Code:
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Audio {
public static final Clip JUMP = grabAudio("jump.wav");
public static Clip grabAudio(final String PATH) {
try {
final Clip CLIP = AudioSystem.getClip();
final AudioInputStream AIS = AudioSystem
.getAudioInputStream(Audio.class.getResourceAsStream(PATH));
CLIP.open(AIS);
return CLIP;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void playAudio(final Clip CLIP) {
CLIP.setFramePosition(0);
CLIP.start();
}
}
Thanks in advance