3

I'm using JAAD with SPI to play m4a files through JavaSound, which I have working fine.

However, I'd like to support a number of formats in this way - but whenever I try and play another format, JAAD seems to try to deal with it and then fail (obviously because it only deals with AAC.)

I'm assuming this is a bug in JAAD, since all the other SPI libraries play fine with each other. Is there a nice way to work around it until it's fixed, or is there another AAC library that works with Javasound which I can use?

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • *"all the other SPI libraries"* Are you implying that JAAD (never heard of it) provides an SPI for AAC? If so, find that Jar and add it to the run-time class-path of your (other) projects. – Andrew Thompson May 20 '12 at 00:37
  • @AndrewThompson Sorry for the confusion - yup JAAD provides an SPI for AAC. The problem isn't getting it working with other projects, the problem is getting it working with other SPIs, such as mp3SPI, JFlac and so on - it essentially "hogs" all the formats, trying to play them all, and just failing if it can't (rather than just trying to play AAC audio.) I can work around it (ish) by checking file extensions or could try to patch JAAD - I was just wondering if anyone else had any better ideas. – Michael Berry May 20 '12 at 13:52

2 Answers2

3

There is a workaround using jaad created by Michael Berry: this is the url

https://code.google.com/p/quelea-projection/source/browse/Quelea/src/org/quelea/sound/AudioTrack.java?spec=svn0352523f49cf20d41d1a7dc098af1db38000cc6d&r=0352523f49cf20d41d1a7dc098af1db38000cc6d

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
Juan Pablo
  • 46
  • 2
2

Since it took me a while to find berry150's code, here is the solution: First, you have to order the jars in the classpath so that JLayer, MP3SPI and Tritonous Share are loaded before JAAD. Then for getting the AudioInputStream, use the following code:

if (getAudioFormat().equals(".mp3")) {
    audioStream = AudioSystem.getAudioInputStream(file); // Obtains an audio input stream of the song
            }
else if (getAudioFormat().equals(".m4a")){
    audioStream = new AACAudioFileReader().getAudioInputStream(file);
            }

So what happens is that if the audio is mp3, the getAudioStreamMethod() from Javasound will be called first since its JAR was loaded first. If the audio is .m4a, a new instance of the ACCAudioFileReader() is created and the getAudioInputStream() of the JAAD library is called.

amb110395
  • 1,545
  • 13
  • 16
  • hi amb, I have been researching JAAD for 1 and a half month.. I was trying to give up but I want to give JAAD 1 last try. However, I tried everything that I could, I still got the error when proceed .m4a file.. Does JAAD load JLayer, MP3SPI and Tritonous as well?? – taymedee May 28 '14 at 02:19
  • Hey taymede, its been awhile since I worked on this but I think the order for loading should be: JLayer, MP3SPI, Tritonous Share and then the last one should be JAAD. This is arranged in your project's classpath – amb110395 May 28 '14 at 16:12