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

Started by Cottonwood, December 18, 2010, 12:01:33

Previous topic - Next topic

Cottonwood

Quote from: jediTofu on December 17, 2010, 20:31:20
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.
"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)
Regards. Cottonwood.

Matthias

Just use the mp3 decoder library (like jlayer3) and stream the sound through OpenAL.

Cottonwood

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.

Matthias

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.

Cottonwood

Sorry, but I think we don't understand each other. How can I play mp3 with slick or ogg without?
Regards. Cottonwood.

Cottonwood

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)
Regards. Cottonwood.

jediTofu

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

Cottonwood

Quote from: Cottonwood on December 20, 2010, 23:51:05What I did ... 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.

Yes I know. But that was what didn't work with windows. And with linux I don't use Eclipse. With linux I have a JRE and the lwlgl libraries only. And until now there works ogg only.

My test environment is windows. But I sometimes check whether my program works with linux too. Because it is important for me that it works without expensive software too. Not really for this program as it is now. I'm just beginning to learn java programming. More than this for the programs that I maybe create in the future. ;)

"it will be worth it, if not for the sake of this song but for the sake of your own peace of mind." ©1967 by Eric Burdon, Vic Briggs, John Weider, Barry Jenkins and Danny McCulloch.
Regards. Cottonwood.

broumbroum

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]

broumbroum

Mp3 is playing fine with JLayer. I see a JOrbis library that can play ogg, too. http://www.jcraft.com/jorbis/.