From cb14a977a9ee1a37c8881dcecac256479cd66b61 Mon Sep 17 00:00:00 2001 From: Mythical-Atlas Date: Wed, 13 May 2020 22:08:43 -0400 Subject: [PATCH] fixed issue with sound loading objectsounds was misspelt objectSounds, but for some reason it only failed to load when running as a jar file? no idea why it worked in the ide... --- Sonic Fan Game/src/main/Loader.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sonic Fan Game/src/main/Loader.java b/Sonic Fan Game/src/main/Loader.java index 914e771..f877267 100644 --- a/Sonic Fan Game/src/main/Loader.java +++ b/Sonic Fan Game/src/main/Loader.java @@ -8,6 +8,7 @@ import java.nio.ByteBuffer; import javax.imageio.ImageIO; +import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.FloatControl; @@ -151,7 +152,7 @@ public void init() { stepSound3 = loadSound("/sonicsounds/step3.wav", -10.0f); stepSound4 = loadSound("/sonicsounds/step4.wav", -10.0f); - ringSound = loadSound("/objectSounds/ring.wav", -20.0f); + ringSound = loadSound("/objectsounds/ring.wav", -20.0f); hudRingAnim = loadImages("/hudsprites", "ring"); @@ -226,10 +227,17 @@ public ByteBuffer loadImage(String path) { private Clip loadSound(String path, float amp) { Clip sound = null; try { + InputStream is = getClass().getResourceAsStream(path); + BufferedInputStream bis = new BufferedInputStream(is); + AudioInputStream ais = AudioSystem.getAudioInputStream(bis); + sound = AudioSystem.getClip(); - sound.open(AudioSystem.getAudioInputStream(new BufferedInputStream(getClass().getResourceAsStream(path)))); + sound.open(ais); + } + catch (Exception e) { + System.err.println("Faied to load sound '" + path + "'"); + e.printStackTrace(); } - catch (Exception e) {e.printStackTrace();} FloatControl gainControl = (FloatControl)sound.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(amp);