-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSoundManager.java
57 lines (47 loc) · 1.59 KB
/
SoundManager.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
57
import fallk.logmaster.HLogger;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SoundManager {
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final HashMap<String, SoundClip> clips = new HashMap<>();
public void add(String name, SoundClip clip) {
clips.put(name, clip);
}
public void play(String name) {
SoundClip soundClip = clips.get(name);
if (soundClip != null) {
if (soundClip instanceof SoundClipThreaded) {
executor.execute(((SoundClipThreaded) soundClip));
} else {
soundClip.play();
}
} else {
HLogger.warn("clip not found: " + name);
}
}
public void stop(String name) {
SoundClip soundClip = clips.get(name);
if (soundClip != null) {
if (soundClip instanceof SoundClipUnthreaded) {
soundClip.stop();
} else {
HLogger.warn("threaded clips cannot be stopped! " + name);
}
} else {
HLogger.warn("clip not found: " + name);
}
}
public void loop(String name) {
SoundClip soundClip = clips.get(name);
if (soundClip != null) {
if (soundClip instanceof SoundClipUnthreaded) {
soundClip.loop();
} else {
HLogger.warn("threaded clips cannot be looped! " + name);
}
} else {
HLogger.warn("clip not found: " + name);
}
}
}