I was messing around seeing what I could do with a basic soundloader, and this was the result.
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Sound {
public static Sound exampleSound = loadSound("/soundPath/yoursound.wav");
private Clip clip;
public static Sound loadSound(String fileName) {
Sound sound = new Sound();
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(Sound.class
.getResource(fileName));
Clip clip = AudioSystem.getClip();
clip.open(ais);
sound.clip = clip;
} catch (Exception e) {
System.out.println(e);
}
return sound;
}
public void loop(final int count) {
try {
if (clip != null)
new Thread() {
public void run() {
synchronized (clip) {
clip.stop();
clip.setFramePosition(0);
clip.loop(count);
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void stop() {
try {
if (clip != null)
new Thread() {
public void run() {
synchronized (clip) {
clip.stop();
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void play() {
try {
if (clip != null)
new Thread() {
public void run() {
synchronized (clip) {
clip.stop();
clip.setFramePosition(0);
clip.start();
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It’s not brilliant or anything amazing, but I figured I’d share it.