Mike
Mike

Reputation: 109

Unable to locate sound file (.ogg)

I have a method called setSound() which is setting up a queue and adding a track to it and then playing it. I call the method in simpleInitGame(). However no sound plays and the console in eclipse says:

Mar 13, 2012 10:15:55 PM com.jmex.audio.openal.OpenALSystem setupSourcePool
INFO: max source channels: 32
Mar 13, 2012 10:15:55 PM com.jme.util.resource.ResourceLocatorTool locateResource
WARNING: Unable to locate: src/com/preston/sounds/background.ogg
Mar 13, 2012 10:15:55 PM com.jmex.audio.openal.OpenALSystem createAudioTrack
WARNING: Could not locate audio file: src/com/preston/sounds/background.ogg

Here is the method:

protected void setSound()
    {
        audio = AudioSystem.getSystem();
        sound1 = audio.createAudioTrack("src/com/preston/sounds/background.ogg", false);
        queue = AudioSystem.getSystem().getMusicQueue();
        queue.setCrossfadeinTime(0);
        queue.setRepeatType(RepeatType.ONE);
        queue.addTrack(sound1);
queue.play();

    }

I don't think it's the directory as my textures are in the same directory (except instead of preston/sounds its preston/textures).

Upvotes: 1

Views: 192

Answers (2)

Remo
Remo

Reputation: 66

Most likely you can omit the "src/" prefix. The Eclipse compiler will compile all java files into class files and in addition copy the resources from your sources to "bin/". I think JME then uses ClassLoader.getResourceAsStream(...) to load assets from the classpath. So, try removing "src/".

Upvotes: 1

Zoltán
Zoltán

Reputation: 22196

this is most probably a problem with your relative path. The default directory of the ResourceLocatorTool in jMonkeyEngine is not the root of your project. Try to open it with an absolute path and see if it works.

Also, the location of your file is not a wise choice. The src folder is intended for java source files, not resources. You should put them in assets/Sounds. See jME best practices

Upvotes: 1

Related Questions