-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.java
More file actions
54 lines (38 loc) · 1.11 KB
/
Sound.java
File metadata and controls
54 lines (38 loc) · 1.11 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
44
45
46
47
48
49
50
51
52
53
54
import java.io.File;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Sound {
Clip clip;
URL soundURL[] = new URL[30];
File file = new File("BGMusic.wav");
File file2 = new File("ClickSound.wav");
public void setFile(int i) {
if(i==0){
try{
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(ais);
}catch(Exception e){
}
}
else if(i==1){
try{
AudioInputStream ais = AudioSystem.getAudioInputStream(file2);
clip = AudioSystem.getClip();
clip.open(ais);
}catch(Exception e){
}
}
}
public void play() {
clip.start();
}
public void loop() {
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
public void stop() {
clip.stop();
}
}