-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSounds.java
More file actions
63 lines (59 loc) · 1.71 KB
/
Copy pathSounds.java
File metadata and controls
63 lines (59 loc) · 1.71 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
55
56
57
58
59
60
61
62
63
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;
public class Sounds {
public static void playSound(String event) {
File soundFile = new File("sounds\\"+event+".wav");
try {
AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.setFramePosition(0);
clip.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void playClickSound() {
playSound("buttonClick");
}
public static void playRadioClickSound() {
playSound("pick");
}
public static void playMatchingCardSound() {
playSound("plus");
}
public static void playFlipSound() {
playSound("flipCard");
}
public static void playGameOverSound() {
playSound("GameOver");
}
public static void playNewScoreSound() {
playSound("newHighScore");
}
public static void playWinSound() {
playSound("win");
}
static class timerSound {
File soundFile = new File("sounds\\timer.wav");
Clip clip;
public timerSound() {
try {
AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
clip = AudioSystem.getClip();
clip.open(audioIn);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void play() {
clip.setFramePosition(0);
clip.start();
}
public void stop() {
clip.stop();
}
}
}