Hey folks,
I’m trying to test my project as a runnable jar file instead of running it from the Eclipse environment, and I’m having trouble getting it to recognize .mp3 assets.
I’m using the the following .jar files to enable the native audio library to run compressed formats:
jl1.0.1.jar
mp3spi.1.9.5.jar
tritonus_share.jar
Here are the constructors for my sound class:
private SoundClip(String filename) {
String path = "sfx/" + filename;
try {
InputStream src = getClass().getClassLoader().getResourceAsStream(path);
InputStream bufferedIn = new BufferedInputStream(src);
input = AudioSystem.getAudioInputStream(bufferedIn);
AudioFormat baseFormat = input.getFormat();
AudioFormat decodeFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false
);
AudioInputStream decodedInput = AudioSystem.getAudioInputStream(decodeFormat, input);
clip = AudioSystem.getClip();
clip.open(decodedInput);
gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (Exception e) {
e.printStackTrace();
}
}
private SoundClip(String filename, float gain){
this(filename);
setGain(gain);
}
I can load and play mp3’s just fine from the Eclipse environment, but when I try to run the jar as a standalone, it throws this:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:14)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:15)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:16)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:17)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:18)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:19)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:20)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:21)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.media.sound.RIFFReader.read(Unknown Source)
at com.sun.media.sound.RIFFReader.(Unknown Source)
at com.sun.media.sound.WaveFloatFileReader.internal_getAudioFileFormat(Unknown Source)
at com.sun.media.sound.WaveFloatFileReader.getAudioFileFormat(Unknown Source)
at com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:37)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:61)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:23)
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
Exception in thread “main” java.lang.ExceptionInInitializerError
at com.noah.breakit.game.Game.(Game.java:71)
at com.noah.breakit.game.Game.main(Game.java:159)
Caused by: java.lang.NullPointerException
at com.noah.breakit.assets.SoundClip.setGain(SoundClip.java:94)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:62)
at com.noah.breakit.assets.SoundClip.(SoundClip.java:23)
… 2 more
If anybody has any ideas about where the error is, I’m all ears!