I made it so that I could stream music in the background of my game. It seems like others might find it usefull, so I’ve released the code:
http://home.halden.net/tombr/ogg/ogg.html
Enjoy!
I made it so that I could stream music in the background of my game. It seems like others might find it usefull, so I’ve released the code:
http://home.halden.net/tombr/ogg/ogg.html
Enjoy!
Thanks for this nice piece of code. It helped me to solve an important problem in our game for university.
basti
Glad you found it usefull.
I’m a bit curious. What was the problem you had?
The only problem was that I’ve been to silly to get that ogg-stuff working for backgroundmusic :). maybe i should smoke less and learn more…
Bug report:
public long skip(long n) throws IOException
{
int bytesRead = 0;
while (bytesRead < n)
{
int res = read();
if (read() == -1)
{
break;
}
bytesRead++;
}
return bytesRead;
}
Note:
int res = read();
if (read() == -1)
{
break;
}
If you skip(n) you actually skip n*2 bytes.
Presuming you’re talking about the int:
read() actually reads only a single byte, not an int, it just returns an int. If it read an int, it was actually be n4, not n2?
Kev
No.
read() is called TWICE every loop-iteration :
I didn’t expect the need to clarify that, because
it was so obvious, but it seems I should have
done it in my first reply.
Fix:
int res = read();
if(res == -1)
{
break;
}
Doh!
Kev
Thanks Skippy! It’s fixed and website updated.
… and who’s too dumb to get it up and running? it’s me (again) :-/
i download lwjgl and jorbis according to the instructions, placed the jar’s and dll’s in my classpath but it doesn’t compile:
OggPlayer.java:52: cannot resolve symbol
symbol : method alGenBuffers (java.nio.IntBuffer)
location: class org.lwjgl.openal.AL
AL.alGenBuffers(buffers);
the import of org.lwjgl.openal.AL is recognized, so i guess i mounted the jars correctly. but why is this method not recognized?
I wrote the code a year ago using lwjgl version 0.94 or something. Everytime lwjgl comes in a new version it breaks, and I haven’t been updating the source on the website.
I think all you have to do is replace all “AL.” with “AL10.”
did that and it fixed a lot of the compiler errors. thx.
but i still have “unknown symbol” errors on these three lines:
163: AL10.alBufferData(buffer, format, dataBuffer, bytesRead, oggInputStream.getRate());
250: AL10.create();
261: AL10.destroy();
sorry for bothering you with this but i have absolutely no knowledge of openal and i really want to use your class because streaming ogg sound seems to be the perfect solution for my game.
AL10.alBufferData(buffer, format, dataBuffer, oggInputStream.getRate());
AL.create();
AL10.destroy();
Lwjgl javadoc. I have to warn you that the OggPlayer is not perfect, and is only there to give you an example of how to use OggInputStream. You may have to improve it yourself.
works now, thanks. lets see if i can modify that thing to loop the ogg file…