2

I'm trying to develop a java application for the raspberry pi that will play mp3s.

I wrote a simple program to see if it would work using JLayer

Code for the app is like this:

public static void main(String[] args) {        
    Player player = null;

    try {
        FileInputStream fis = new FileInputStream("song.mp3");
        BufferedInputStream bis = new BufferedInputStream(fis);
        player = new Player(bis);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    try {
        player.play();
    } catch (JavaLayerException e) {
        System.out.println(e.getMessage());
    }   
}

The program runs on windows but on the pi when creating the new player object I am getting the exception:

Cannot create AudioDevice

Has anyone been able to get JLayer working on the pi?

I'm using the latest Soft-float Debian “wheezy” image with the Orcale JVM.

Simulant
  • 643
  • 1
  • 9
  • 22
Matthew Wilson
  • 171
  • 2
  • 7
  • You're better off using `printStackTrace()` as it gives a lot more information than `getMessage()` when it comes to debugging. I've just tried the above and I get the same error (openjdk6). I changed it to printStackTrace() and I get: `java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 22050.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.` Not sure how to fix this though. – Munkeh Oct 28 '12 at 23:00
  • After some searching, I found this thread which should help: http://raspberrypi.stackexchange.com/questions/1337/how-can-i-get-java-sound-to-work – Munkeh Oct 28 '12 at 23:12
  • I would say that [this](http://raspberrypi.stackexchange.com/a/1340/40) is the problem (again). – Jivings Oct 29 '12 at 07:50
  • So did you have any luck with openjdk7? I run arch-arm on my pi so I can't test. As above though, you're gonna get poor performance decoding mp3 in real time. You're better off running a program written in C (mpg123, etc.) for performance. – Munkeh Oct 29 '12 at 22:36

1 Answers1

1

I got this working. I had installed the Oracle JRE but it wouldn't play, but when I installed the Oracle JDK the mp3 played ok. The performance is good which was a nice surprise!

Matthew Wilson
  • 171
  • 2
  • 7
  • Same here - downloaded ejre-7u21-fcs-b11-linux-arm-vfp-client_headless-04_apr_2013.tar.gz and it couldn't find audio device, so I changed to JDK jdk-7u21-linux-arm-sfp.tar.gz (taken from usual JDK download page) and it worked. – mvmn Aug 16 '13 at 19:02