Skip to content

Commit

Permalink
Improve Audio code stability
Browse files Browse the repository at this point in the history
  • Loading branch information
redomar committed Feb 2, 2024
1 parent 61b7d66 commit 41d217e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/com/redomar/game/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AudioHandler(String path, boolean music) {

private void check(String path) {
try {
if (!path.equals("")) {
if (!path.isEmpty()) {
initiate(path);
} else {
throw new NullPointerException();
Expand Down Expand Up @@ -89,14 +89,22 @@ public void setVolume(float velocity) throws NullPointerException {
}

public void stop() {
if (clip.isRunning()) clip.stop();
if (music) musicPrinter.print("Stopping Music");
active = false;
try {
if (clip == null) throw new RuntimeException("Empty clip");
if (clip.isRunning()) {
clip.stop();
clip.close();
}
} catch (Exception e) {
musicPrinter.print("Audio Handler Clip not found");
} finally {
if (music) musicPrinter.print("Stopping Music");
active = false;
}
}

public void close() {
stop();
clip.close();
}

public boolean getActive() {
Expand Down

0 comments on commit 41d217e

Please sign in to comment.