Music in Java Program
Hi, I have been searching all over Google on how to add music to a Java game that I created. I'm wanting it to be like background. I was hoping for some simple code, but have yet to find any. I have the songs selected and have also found out that I probably have to use a .wav file rather than a
.mp3 file (which is perfectly fine since I have a .wav converter). If anyone could help me out a little bit then that would be great and I'd really appreciate it. Thanks.
There are essentially two routes:
- the JavaSound API is part of the standard JDK (in other words, anyone with a recent version of Java will have it); you're effectively limited to WAV format, or else writing the decoder yourself (there must be a free Java implementation of an Ogg Vorbis decoder); if you're writing an Applet, this is really the only option;
- the Java Media Framework (JMF) does support MP3, among other things, but it means your users have to download and install this extra component.
Note that the other problem with MP3 is that it's not a free format: in principle, if you write some software that decodes MP3-- or in any way embed an MP3 decoder in your application-- you're supposed to pay an extortionate licence for the privilege. (Clarification: if you use JMF, I think you're OK.)