Sun, Audio-player and Sound I/O

sun.audio is undocumented

Like other sun.* packages, it is undocumented and it might disappear.

Java Media Framework is old

It’s an optional package, not part of the SE and hasn’t been updated in a long time. Oracle has a page on it and it’s still available but, well, who knows what will happen to it.

javax.sound is part of the SE

This is the current Java sound implementation, it is part of the SE and the tutorial for it can be found here. If you want to use audio in Java this is what you should learn because it’s official, it works, it gets updated sometimes and it is well-documented.

javax.sound does not play mp3

Why is that? Despite being ubiquitous in file systems, mp3 has a history of licensing and patent issues. Mp3 is a minefield and this may be why Sun/Oracle has not put effort in to supporting it. (If this is why, I don’t blame them.)

If you really want to play mp3 there are some third-party decoders floating around on the web. There is no point in recommending one because all of them will read mp3.


JavaFX does play mp3

Use a javafx.scene.media.MediaPlayer. See javafx.scene.media/Supported Media Types. JavaFX is part of the JRE/JDK as of Java 8 (and new versions of Java 7) and will (probably) eventually supersede several SE APIs like javax.sound and javax.swing.

Leave a Comment