Hello Guest

[solved] How can I play mp3 and ogg in one java player program?

  • 9 Replies
  • 15493 Views
Slick-Util can play ogg & mp3, so you're good there.

With your help I could realize playing ogg sounds. But I can't find anything about slick and mp3. Google

Background
I have a program that can play mp3 (only) in a windows environment. But it couldn't play ogg. So I thought I had to find out how to play ogg.
As I could that, I thought I could combine both in one program. But the mp3 runs only without the slick libraries.
As soon as I added the slick libraries to the eclipse runtime environment I got an error message when playing mp3. Without any change within the code.
Code: [Select]
"file:///D:/Musik/Musik-DVD1/Albert Hammond - Down By The River.mp3"
  Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Mono, LittleEndian, Signed, 16000.0 frame rate, FrameSize=16384 bits
Failed to realize: com.sun.media.PlaybackEngine@118f375
Error: Unable to realize com.sun.media.PlaybackEngine@118f375
java.lang.NullPointerException
at MusicPlayer.run(MusicPlayer.java:114)
at java.lang.Thread.run(Unknown Source)
« Last Edit: December 20, 2010, 23:53:31 by Cottonwood »
Regards. Cottonwood.

Re: How can I play mp3 and ogg in one java player program?
« Reply #1 on: December 18, 2010, 12:42:55 »
Just use the mp3 decoder library (like jlayer3) and stream the sound through OpenAL.

Re: How can I play mp3 and ogg in one java player program?
« Reply #2 on: December 18, 2010, 13:08:38 »
Sorry, but I don't understand what you're meaning. I can play mp3, but only without slick libraries. And I can play ogg/vorbis, but only with slick libraries. And that doesn't fall into place.
Regards. Cottonwood.

Re: How can I play mp3 and ogg in one java player program?
« Reply #3 on: December 18, 2010, 13:31:47 »
Playing music works like this:
- you have a decoder library which converts bytes to audio samples
- you have a audio playback library to play these audio samples

LWJGL offers OpenAL for audio playback and also recording.
Slick(-Utils) just offers some wrapper around OpenAL and some decoders.

You can always use OpenAL directly without Slick(-Utils) or you can use or extend Slick-(Utils) code to playback your music.

Re: How can I play mp3 and ogg in one java player program?
« Reply #4 on: December 18, 2010, 14:00:47 »
Sorry, but I think we don't understand each other. How can I play mp3 with slick or ogg without?
Regards. Cottonwood.

Re: How can I play mp3 and ogg in one java player program?
« Reply #5 on: December 20, 2010, 23:51:05 »
Now I can play mp3 as well as ogg without changing anything. What I did before (what I wrote about) was to change the VM arguments as you can see on the shot 1. With the -Djava.library.path=..\lwjgl\native\windows it worked for ogg, without it worked for mp3. That wasn't really a solution.

After some tests I found out that it works for both when I copy the modules from -Djava.library.path=..\lwjgl\native\windows directly into the working directory and without setting VM arguments.

That brought me to the idea to set the working directory to the -Djava.library.path=..\lwjgl\native\windows without copying libs and without setting the VM arguments. And that also works. For me it is the best solution I can get at the moment. (shot 2)
« Last Edit: December 21, 2010, 00:19:14 by Cottonwood »
Regards. Cottonwood.

Re: [solved] How can I play mp3 and ogg in one java player program?
« Reply #6 on: December 21, 2010, 05:04:21 »
You should be linking your libraries anyway to use LWJGL (i.e., -Djava.library.path=<path>).

Don't make the same mistake I did; don't rely on working directory.  Linux's JVM, for whatever reason, doesn't include the current directory in java.library.path automatically.
For distribution, use JNLP, Applets, or if you really have to OS-specific stuff (microsoft batch scripts, shell/bash unix scripts, or online programs that can make exe's/elf's or by using gcj compiler).
cool story, bro

Re: How can I play mp3 and ogg in one java player program?
« Reply #7 on: December 21, 2010, 06:37:26 »
Regards. Cottonwood.

Re: [solved] How can I play mp3 and ogg in one java player program?
« Reply #8 on: December 21, 2010, 20:30:34 »
CotonWood, you seem to ask for how to load natives from an external path than the LWJGL/SLick one. I think linux and windows have a common library path you can use, it is the user.home directory. Anyway, if it is not the case, System.load() can help ( http://download.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#load(java.lang.String) ). it can load a library located at any folder you want.

[I should have put it in another Thread, because it is maybe off-topic so here's the end of this post]

Re: [solved] How can I play mp3 and ogg in one java player program?
« Reply #9 on: December 21, 2010, 20:40:37 »
Mp3 is playing fine with JLayer. I see a JOrbis library that can play ogg, too. http://www.jcraft.com/jorbis/.