-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.java
More file actions
31 lines (24 loc) · 754 Bytes
/
Copy pathSound.java
File metadata and controls
31 lines (24 loc) · 754 Bytes
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
import java.io.File;
import javax.sound.sampled.*;
public class Sound {
/*
playClip
plays a specified .wav file
*/
public static void playClip(File file) {
try {
final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
}
}
});
clip.open(AudioSystem.getAudioInputStream(file));
clip.start();
} catch (Exception exc) {
exc.printStackTrace(System.out);
}
}
}