Java AudioInputStream works on one project, but not the other

174 views Asked by At

So I have been trying to add sounds in my game but I get an error when I initialize my AudioPlayer class when reading the resource stream. I tested this on another game project and it worked fine with no errors, so it is something weird. Here's my code for the AudioPlayer:

public class AudioPlayer 
{
    private Clip clip;

public AudioPlayer(String s)
{
    try{
        AudioInputStream ais = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(s));
        AudioFormat baseFormat = ais.getFormat();
        AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
        AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);

        clip = AudioSystem.getClip();
        clip.open(dais);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

     //methods here    

}

And here is the error log:

Exception in thread "main" java.util.ServiceConfigurationError: javax.sound.sampled.spi.AudioFileReader: Error reading configuration file
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.parse(ServiceLoader.java:309)
at java.util.ServiceLoader.access$200(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at com.sun.media.sound.JSSecurityManager$3.run(JSSecurityManager.java:180)
at com.sun.media.sound.JSSecurityManager$3.run(JSSecurityManager.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.media.sound.JSSecurityManager.getProviders(JSSecurityManager.java:184)
at com.sun.media.sound.JDK13Services.getProviders(JDK13Services.java:109)
at javax.sound.sampled.AudioSystem.getProviders(AudioSystem.java:1631)
at javax.sound.sampled.AudioSystem.getAudioFileReaders(AudioSystem.java:1406)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1107)
at main.audio.AudioPlayer.<init>(AudioPlayer.java:18)
at main.states.Game.<init>(Game.java:65)
at main.states.Game.main(Game.java:291)
Caused by: java.io.FileNotFoundException: C:\Users\Matthew\Desktop\lots of fun (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:103)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:94)
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
at java.net.URL.openStream(URL.java:1045)
at java.util.ServiceLoader.parse(ServiceLoader.java:304)
1

There are 1 answers

0
Lee Chu On

My project folder was called "lots of fun!", and after renaming it w/o the "!" it worked so don't put symbols in your folder names kids.