Skip to content

Commit 41d217e

Browse files
committed
Improve Audio code stability
1 parent 61b7d66 commit 41d217e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/com/redomar/game/audio/AudioHandler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public AudioHandler(String path, boolean music) {
3333

3434
private void check(String path) {
3535
try {
36-
if (!path.equals("")) {
36+
if (!path.isEmpty()) {
3737
initiate(path);
3838
} else {
3939
throw new NullPointerException();
@@ -89,14 +89,22 @@ public void setVolume(float velocity) throws NullPointerException {
8989
}
9090

9191
public void stop() {
92-
if (clip.isRunning()) clip.stop();
93-
if (music) musicPrinter.print("Stopping Music");
94-
active = false;
92+
try {
93+
if (clip == null) throw new RuntimeException("Empty clip");
94+
if (clip.isRunning()) {
95+
clip.stop();
96+
clip.close();
97+
}
98+
} catch (Exception e) {
99+
musicPrinter.print("Audio Handler Clip not found");
100+
} finally {
101+
if (music) musicPrinter.print("Stopping Music");
102+
active = false;
103+
}
95104
}
96105

97106
public void close() {
98107
stop();
99-
clip.close();
100108
}
101109

102110
public boolean getActive() {

0 commit comments

Comments
 (0)