Skip to content

Commit

Permalink
Use resources directory for SoundManager audio files
Browse files Browse the repository at this point in the history
This makes SoundManager actually find the audio clips, previously it
failed silently. The only code playing audio at the moment is a
notification sound to a lobby host whenever someone joins their lobby,
however further commits will expand on audio functionality.
  • Loading branch information
StenAL committed Apr 28, 2023
1 parent 4836e4d commit 06f0e00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Tested:

## Problems
- Ratings are not synced
- No sound
- Custom Tracks category disabled
- Server sometimes crashes due to race conditions

Expand Down
19 changes: 2 additions & 17 deletions client/src/main/java/com/aapeli/client/SoundManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.aapeli.applet.AApplet;

import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
Expand Down Expand Up @@ -35,12 +34,8 @@ public SoundManager(AApplet applet, boolean loadClipsOnRegister, boolean debug)
this.loadSoundClipsOnRegister = loadClipsOnRegister;
this.debug = debug;
this.loadClientSounds();
this.sharedSoundDir = applet.getCodeBase();
this.sharedSoundDir = this.getClass().getResource("/sound/shared/");

try {
this.sharedSoundDir = new URL(this.sharedSoundDir, "src/main/resources/sound/");
} catch (MalformedURLException var5) {
}
this.sharedSounds = new Hashtable<>();
this.clipLoaderThreadRunning = false;
if (loadClipsOnRegister) {
Expand Down Expand Up @@ -208,17 +203,7 @@ protected boolean isDebug() {
}

private void loadClientSounds() {
URL clientSoundsDir = this.applet.getCodeBase();

try {
if (FileUtil.isFileUrl(clientSoundsDir)) {
clientSoundsDir = new URL(clientSoundsDir, FileUtil.RESOURCE_DIR + "src/main/resources/sound/");
} else {
clientSoundsDir = new URL(clientSoundsDir, "../Shared/sound/");
}
} catch (MalformedURLException var3) {

}
URL clientSoundsDir = this.getClass().getResource("/sound/shared/");

this.clientSounds = new Hashtable<>();
this.defineSoundClip(1, clientSoundsDir, "challenge");
Expand Down

0 comments on commit 06f0e00

Please sign in to comment.