I have a Java-based MP3 player based on the JLayer / BasicPlayer framework which I'd like to get running on the Pi. I have installed the OpenJDK on the most current Raspbian. The BasicPlayer opens the line correctly, but only get stuttering noise when playing back a file.

Playing back sound using the mpg123 command line tool works fine.

Is there something wrong with the Java Sound implementation of the ARM OpenJDK?

I'm thankful for any hints in the right direction.

This is the code:

BasicPlayer pl = new BasicPlayer();
try {
    String path = "/home/pi/Music/testmp3.mp3";
    File file = new File(path);
} catch (Exception e) {


  • I would guess that this would mean that the mp3 decoding would be taking place in software. I seriously doubt the Pi would be capable enough to do that.
    – Jivings
    Commented Jul 29, 2012 at 21:23
  • one possible reason could be bigendian/littleendian confusion in the decoder. Commented Jul 29, 2012 at 23:13
  • Thorbjørn: Interesting, will that result in the stuttering, distorted noise?
    – nanoman
    Commented Aug 1, 2012 at 7:46

4 Answers 4


I do not have enough score to make comments. So I'll post here:

1-"Not enough CPU"- I used to do mp3 decoding by software in a Sparc Station with a 35MHz CPU. So unless that decoder is seriously flawed it should work.

Can you do the full decode to a file? If yes measure the time it takes. If it is less that the total runtime of the song you are in business. Afterwards copy the undecode file to another machine and see if the wav is ok.


I did some tests with JLayer1.0.1 on my RPI and it is slow:

time java -cacao -classpath jl1.0.1.jar javazoom.jl.converter.jlc file.mp3 -p out.wav

Takes 3 times more to decode than the runtime of the song.

[EDIT 2]:

Managed to decode a mp3 in less time than the runtime using Java SE Embedded 6 http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html :

pi@raspbmc:~/java/JLayer1.0.1$ rm out.wav; time ../ejre1.7.0_04/bin/java -classpath jl1.0.1.jar javazoom.jl.converter.jlc Gill\ Scott-Heron-\ The\ Revolution\ Will\ Not\ Be\ Televised.mp3 -p out.wav FileName = Gill Scott-Heron- The Revolution Will Not Be Televised.mp3

real 0m57.624s user 0m49.900s sys 0m2.320s

On a 3 minutes wav.

Problem is that it does not work on raspbian:


  • Thanks for the explanation - what distribution are you using?
    – nanoman
    Commented Aug 1, 2012 at 7:44
  • These tests were done with raspbmc rc3. But no xbmc or X was running. Commented Aug 2, 2012 at 21:31

Here's your problem:

by MartenR » Thu Jul 05, 2012 11:09 am

Sound is always done on the cpu for codecs other than the free codecs, no licenses bought for sound decoding for mpeg audio or ac3.

The Raspberry Pi is simply not powerful enough to decode the mp3 in real time in software when running on the JVM.

You can try a few things to make it work:

  • Increase the memory available to the CPU

  • Try running a player that is not restricted by the JVM (though I have no idea if this will yield any improvement...)

     Runtime.getRuntime().exec("omxplayer [filename]");
  • That should not give static but looping fragments. Commented Jul 29, 2012 at 23:00
  • @ThorbjørnRavnAndersen: Is that relevant to my answer? Except for the Java part?
    – Jivings
    Commented Jul 30, 2012 at 7:28
  • Well, yes, if the symptom indicate something else. Commented Jul 30, 2012 at 7:40
  • @ThorbjørnRavnAndersen: I don't understand what you mean. Can you explain?
    – Jivings
    Commented Jul 30, 2012 at 7:40
  • Static happens when the wrong bytes are fed to the sound circuitry. If the software is slow the right bytes are fed, but not fast enough so the buffers used contain stale data, causing the sound in the buffer to loop. At least that is how I've seen that symptom on other systems. Commented Jul 30, 2012 at 7:46

If any application can play sound smoothly using the CPU, then all applications should be able to play it smoothly.

OpenJDK 6 has problems with ALSA (doesn't play to the "default" device for example), so use OpenJDK 7 instead. Also, both OpenJDK versions use the Zero interpreter, which is very slow. You should use a JVM that JITs, such as CACAO on a soft-float distribution, or Avian JVM on a hard-float distribution (such as Raspbian).

  • But can anything play mp3s smoothly? None of my applications can
    – Jivings
    Commented Aug 4, 2012 at 14:09

Great news - I have it running!

I installed the new softfloat Debian wheezy image, then installed the just-released JDK 7 Update 6 on it, and it runs flawlessly. Just make sure you're installing this JDK on a softfloat-based distribution.

CPU consumption while playing back an MP3 is constantly at about 45%.

  • So it was a JVM issue.
    – Jivings
    Commented Aug 20, 2012 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.