-
Notifications
You must be signed in to change notification settings - Fork 0
/
Audio.java
56 lines (50 loc) · 1.51 KB
/
Audio.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.File;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Audio{
Clip audio;
public Audio(int type) {
switch (type) {
case 1:
try {
audio = AudioSystem.getClip();
audio.open(AudioSystem.getAudioInputStream(new File("Sounds/shoot.wav")));
audio.start();
} catch (Exception e) {
System.out.println("" + e);
}
break;
case 2:
try {
audio= AudioSystem.getClip();
audio.open(AudioSystem.getAudioInputStream(new File("Sounds/explosion.wav")));
audio.start();
} catch (Exception e) {
System.out.println("" + e);
}
break;
case 3:
try {
audio= AudioSystem.getClip();
audio.open(AudioSystem.getAudioInputStream(new File("Sounds/invaderkilled.wav")));
audio.start();
} catch (Exception e) {
System.out.println("" + e);
}
break;
}
}
boolean close() {
if (!audio.isRunning())
{
//audio.stop();
//audio.close();
return true;
}
return false;
}
void start() {
audio.start();
}
}