Playing MP3 sound in a Java applet.

Anyone gotten JavaZOOM's MP3 SPI working?

Using their code example at, and R.J. Lorimer's example at (which is essentially the same thing), I can only play AIF and AU files.  When I attempt to play an MP3, I get an error, "javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input URL([path to audio file])."

The procedure in my code is:

      private void mp3Play(URL urlMP3) {
            try {
                  AudioInputStream audioIn = AudioSystem.getAudioInputStream(urlMP3);
                  AudioFormat baseFormat = audioIn.getFormat();
                  AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                                                                                    baseFormat.getChannels() * 2,
                  AudioInputStream dataIn = AudioSystem.getAudioInputStream(decodedFormat, audioIn);
                  byte[] data = new byte[4096];
                  DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
                  SourceDataLine line = null;
                  line = (SourceDataLine)AudioSystem.getLine(info);
                  if (line != null) {
                        int nBytesRead = 0, nBytesWritten = 0;

                        while (nBytesRead != -1) {
                              nBytesRead =, 0, data.length);
                              if (nBytesRead != -1)
                                    nBytesWritten = line.write(data, 0, nBytesRead);

            } catch (Exception e) {
                  System.out.println("MP3 PLAYBACK ERROR: " + e.toString() + "(" + urlMP3.toString() + ")");

Again, this code works fine if I specify an AIF or AU file.  I suspect that the format of the MP3 file that I'm trying to play is incompatible with the code, but I haven't tried encoding the sound differently, yet.


-- MiloDC
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MiloDCAuthor Commented:
Update: Tried different encoding, still no luck...

-- MiloDC
Mick BarryJava DeveloperCommented:
how did u install the mp3 service provider?
MiloDCAuthor Commented:
> Comment from objects

> how did u install the mp3 service provider?

Man, I just put jl1.0.jar, tritonus_share.jar, and mp3spi1.9.4.jar in my CLASSPATH.  No further set-up is outlined on either of the two pages that I mentioned, above; is there more to installing the SPI than this?  If so, is it going to be possible for me to employ the MP3 SPI in an applet?

-- MiloDC
Mick BarryJava DeveloperCommented:
try putting them on your server and adding them in the archive parameter of your applet tag

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MiloDCAuthor Commented:
Awesome, objects, that did it!

I just added ARCHIVE="jl1.0.jar,mp3spi1.9.4.jar,tritonus_share.jar" to the APPLET tag, and it worked.


-- MiloDC
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.