LWJGL
May 25, 2013, 04:21:38 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [solved] How can I play mp3 and ogg in one java player program?  (Read 4778 times)
Cottonwood
Regular nerd
**
Posts: 50



WWW
« on: December 18, 2010, 04:01:33 »

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:
"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)
Logged

Regards. Cottonwood.
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #1 on: December 18, 2010, 04:42:55 »

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

Cottonwood
Regular nerd
**
Posts: 50



WWW
« Reply #2 on: December 18, 2010, 05: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.
Logged

Regards. Cottonwood.
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #3 on: December 18, 2010, 05: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.
Logged

Cottonwood
Regular nerd
**
Posts: 50



WWW
« Reply #4 on: December 18, 2010, 06:00:47 »

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

Regards. Cottonwood.
Cottonwood
Regular nerd
**
Posts: 50



WWW
« Reply #5 on: December 20, 2010, 15: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)
Logged

Regards. Cottonwood.
jediTofu
Prolific Timewaster
****
Posts: 280



« Reply #6 on: December 20, 2010, 21: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).
Logged

cool story, bro
Cottonwood
Regular nerd
**
Posts: 50



WWW
« Reply #7 on: December 20, 2010, 22:37:26 »

What 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. Wink

"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.
Logged

Regards. Cottonwood.
broumbroum
Prolific Timewaster
****
Posts: 316



WWW
« Reply #8 on: December 21, 2010, 12: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]
Logged

Sf3JSwing project, code repo (Apache License) -  http://www.sourceforge.net/p/sf3jswing
Sf3jswing Project Forum - http://apps.sourceforge.net/phpbb/sf3jswing/
broumbroum
Prolific Timewaster
****
Posts: 316



WWW
« Reply #9 on: December 21, 2010, 12:40:37 »

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

Sf3JSwing project, code repo (Apache License) -  http://www.sourceforge.net/p/sf3jswing
Sf3jswing Project Forum - http://apps.sourceforge.net/phpbb/sf3jswing/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!