Playing MP3s with Java

Share this article

In my off hours, I’m building a spanky Web interface for JJukebox, an open source, multi-user MP3 jukebox server. We take our music pretty seriously here at SitePoint HQ, and it’s time our rusty, old, Perl-based MP3 jukebox software got a revamp.

If there is one weak point in the JJukebox server implementation, it’s the audio playback–specifically, the handling of MP3 files. Despite all its cutting-edge vitality, Java’s support for multimedia is in a sad state indeed.

Going by the book, the Java Media Framework API (JMF) is a one stop shop for capture and playback of all kinds of streaming media. Though MP3 support was removed after JMF 2.1.1a due to the same patent issues that are affecting other open source MP3 software, the Windows version of JMF 2.1.1c reinstated MP3 playback by using the MP3 support in Windows, and since November JMF 2.1.1e now has a MP3 plug-in for all supported platforms (Windows, Linux, Solaris, and a cross-platform version).

Unfortunately, JMF is reportedly incompatible (or at least buggy) with Java 5, and the only sign of life for the API is a comment left by the manager of the Java Client Group’s Swing team on April 12th to the effect that they have taken over responsibility for JMF and will have something to announce Real Soon Now. Personally, I couldn’t even get the JMF 2.1.1e installer to run on my Windows system.

Some recent words of wisdom on what should be done with JMF may be found in JMF, wherefor art thou? on Mason Glaves’s blog, and Java Media without Mediocrity on Chris Adamson’s blog. The executive summary: stop the “Weekend at Bernie’s”-esque sham, let JMF die and make room for more qualified options.

Anyway, for the above reasons, JJukebox abandoned JMF for MP3 playback quite some time ago (the CVS comment upon removal of the JMFPlayer class: “JMF is dead. Long live JMF.”), and adopted JavaZoom‘s JavaLayer instead. If MP3 playback with Java is something you need to do, JavaLayer is the best thing out there right now. For most practical applications, you’ll actually want to use JavaZoom’s BasicPlayer API, which talks to Java’s built-in Java Sound API, which can use JavaZoom’s MP3SPI (a wrapper for JavaLayer) for MP3 playback and JavaZoom’s VorbisSPI (a wrapper for JOrbis) for Ogg Vorbis (an MP3 alternative) playback.

Confused yet? Me too, but with the latest versions of all the necessary libraries installed, it actually works pretty well. That isn’t to say there isn’t still room for improvement. According to one JJukebox author:

I’m part of the JJukeBox project (www.jjukebox.com). We’re eager to find a decent ogg/mp3 player, that isn’t based on JMF or JavaLayer (JlGui). Both are completely rubbish, and any patches we submit to JavaZoom (JavaLayer/JlGui) are ignored, and we’ve had to heavily rewrite parts of JlGui to make it remotely usable. I was quite amazed at how poor parts of the project were, in terms of the (non existent) events system, for example.

If you know of a project that will do ogg/mp3s reliably (broken and knackered mp3s/oggs, with a proper events system and the ability to multi-thread) then please let us know!

Kevin YankKevin Yank
View Author

Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week