0

After looking at a couple of audio libraries, I settled on EasyOgg. Most of the samples report that you play sounds like this:

new OggClip("mysfx.ogg").loop();

This crashes with Couldn't find: mysfx.ogg at runtime. I tried several things:

  • Plain filename
  • Relative path from my project root directory
  • Forward-slashes and backslashes

I can't figure out where exactly the file goes, and how to specify the name. It seems like they should be somehow embedded in my application JAR. (I just have them sitting on the file system.)

ashes999
  • 9,925
  • 16
  • 73
  • 124

3 Answers3

1

I fiddled around with it for a while and came up with a solution using InputStreams:

FileInputStream stream = new FileInputStream("file.ogg");
OggClip clip = new OggClip(stream);

This works without including the files in the jar.

Jeinzi
  • 153
  • 3
  • 8
0

I'm not familiar with EasyOgg, but the first thing I would do is pass in the complete location to the file as a sanity check.

new OggClip("/home/someuser/audio/mysfx.ogg").loop();

If you can't count on java being run from the same location every time, you can use an environment variable to point to the location that your files are sitting in.

new OggClip(System.getenv("MY_APP_HOME") + "/audio/mysfx.ogg").loop();

As far as getting to a resource from inside a jar file, have you tried getResource()?

See: Access file in jar file?

Community
  • 1
  • 1
Jason Schindler
  • 2,790
  • 1
  • 13
  • 8
  • I'm not clear on the internals of EasyOgg, and whether it expects a resource file within the JAR. The tutorials I find all reference simple filenames, without path or description of where to put the files. – ashes999 Dec 17 '13 at 02:25
  • I doubt it expects a resource within a jar file. Have you tried my first suggestion? – Jason Schindler Dec 17 '13 at 04:07
  • I haven't. I will try it and report back. – ashes999 Dec 17 '13 at 04:29
  • It didn't work (same error). I know it accepts a relative path, because I downloaded a sample that works, and put that in a temporary directory. Let me dissect it and see. – ashes999 Dec 17 '13 at 17:20
0

I discovered that the OGG files need to be in the JAR file. This is clear from the working zip samples I found on the interwebz.

To use Gradle to zip up every .ogg file in audio, I add this to my jar task:

from fileTree(dir: '.', include: 'audio/**/*.ogg')

This works, except when I debug from Eclipse. A better solution is to create a separate project (I called mine EmbeddedResources) which creates a JAR that only contains .ogg files. Then, I reference this project from my game project, and I'm done.

ashes999
  • 9,925
  • 16
  • 73
  • 124