-1

I want to play an .ogg file, so i found this piece of code. So it downloads .ogg file from the given url and plays it. I've tried it with external files like

ExamplePlayer player = new ExamplePlayer(new File("D:\\sound.ogg").toURI().toURL().toString())

and it works. But when i try this with internal files and get it using

ExamplePlayer.class.getClassLoader().getResource("sound.ogg")

it says that "There is a hole in the first packet data.". I think maybe it doesn't work because of JAR's compression or something.

So questions are: why it doesn't work? how could i fix it? If i can't fix it, is there any other way to play .ogg files using java? Thanks.

UPD: I found a lib, but the problem still the same, it cannot read from jar file. It

Armagidon
  • 1
  • 2

1 Answers1

0

I'm looking at an application I wrote several years ago that uses ogg resources, and seeing that I first import the ogg file to an InputStream object using getResourceAsStream method.

Usually with wav files, importing via the URL is preferred. Unfortunately I don't recall why I did it this way--too much new tech under the bridge. First guess is that it's a requirement from the jcraft code, otherwise I would have used my preferred method.

Even if this works in the context of an IDE, IDK if it will also work after putting the code into a JAR. getResourceAsStream is often dicey in jars.

Before I invest more time, please let us know if switching to getResourceAsStream does the trick. Maybe the fix is that simple!

+++++++++++++ EDIT: Ugh. Looking at my code, I see where I copied a class from JCraft and edited it, supplying an InputStream via wrapper code. The edit was made in order to output float PCM data from the decoder rather than having the decoder play the sound. The float PCM is then saved in a custom object similar to AudioCue, and the app I wrote this for uses that for playback. All I can remember was that it took a lot tweaking to get this to work.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41