1

I have a java project that needs to play mp3 and aac files. I have created a MediaPlayer class that uses generic code to play sound files via the Java Sound API. I have two audo decoding libraries in my CLASSPATH that are registered as Java Sound SPIs. (MP3SPI and JAAD).

The problem is MP3SPI seems to take priority over JAAD. Meaning that when I play an AAC file, MP3SPI throws an exception and (obviously) doesn't play my song. When I remove MP3SPI from the CLASSPATH, the correct SPI (JAAD) is called, and my AAC files plays fine.

As this problem could probably be represented more generically, I'm hoping someone has some experience solving this.

How to provide support for both MP3 & AAC decoding/playback?

Josh A.
  • 374
  • 3
  • 15
  • What file extension are the AAC files? And can the question be stated as *"How to provide support for both MP3 & AAC encoding?"*? If not, please [edit](http://stackoverflow.com/posts/13907681/revisions) (my edit) to your question. – Andrew Thompson Dec 17 '12 at 03:28
  • 1
    I think a fix is provided in JDK 7 to select/deselect providers at runtime. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4666881 – Usman Saleem Dec 17 '12 at 03:56
  • Usman, this fix isn't implemented yet (slated for Java 8). Any other ideas? EDIT: On my Linux box, the conflict doesn't seem to exist, meaning jaad and mp3spi are coexisting nicely... I'll keep investigating. Thanks. – Josh A. Dec 17 '12 at 17:40
  • The filetypes that play correctly depend on where the jar file is in the CLASSPATH. Windows: Only plays AAC if JAAD is first on the classpath, only plays mp3s if mp3spi is first on the classpath. This makes sense. Linux: Works regardless of the order. Linux JVM > Windows JVM? – Josh A. Dec 17 '12 at 23:35

1 Answers1

0

Sounds like MP3SPI is misbehaving and not playing by the spec, i.e. throwing the wrong exceptions or none when it should.

You basically only have two options:

  1. Hack MP3SPI and fix it (take a look at its AudioFileReader implementations and verify that they behave the way it's specified in the javadocs).
  2. Use a different mp3 service provider (this one or one of these for example).

Good luck.

Community
  • 1
  • 1
Hendrik
  • 5,085
  • 24
  • 56