Skip to content

Commit

Permalink
fixed issue with sound loading
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Mythical-Atlas committed May 14, 2020
1 parent a587313 commit cb14a97
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Sonic Fan Game/src/main/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit cb14a97

Please sign in to comment.