-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundEffects.java
More file actions
43 lines (36 loc) · 1.01 KB
/
SoundEffects.java
File metadata and controls
43 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.net.URL;
/**
* Created by Austin on 2014-07-03.
*/
public enum SoundEffects {
JUMP("sound_jump"),
BOSS_DEATH("sound_boss_death"),
HIT("sound_hit"),
LOSE("sound_lose"),
WIN("sound_win"),
SHOOT("sound_shoot");
private Clip clip;
private SoundEffects(String fileName) {
try {
URL url = this.getClass().getClassLoader().getResource("assets/" + fileName + ".wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
clip = AudioSystem.getClip();
clip.open(audioInputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
public void play() {
if (clip.isRunning()) {
clip.stop();
}
clip.setFramePosition(0);
clip.start();
}
public static void init() {
values(); // preload all sounds.
}
}