Sergey has posted 7 posts at DZone. You can read more from them at their website. View Full User Profile

Playing MP3 Files in JavaFX

  • submit to reddit

This example shows you how to modify the code in an MP3 file. You need to add several new functions to enable the application to read MP3 tags. Then, you should add the resulting JAR to the references of a NetBeans project and create a Java FX form to play the file.

Among several existing libraries for playing MP3 files, the most popular library is JLayer


This small application plays an MP3 file in loop.


package javafxmp3player;

import javafx.ui.*;
import embeddedmp3player.MP3Player;
import embeddedmp3player.MP3File;
import embeddedmp3player.IDone;

var mp3="G:\\mz\\slade\\1\\07-Slade In Flame (1974)\\03-So Far So Good.mp3";
var f = new MP3File(mp3);
var doneCather=new IDone() {
operation done() {;

Frame {
visible: true
screenx: 50
screeny: 100
width: 300
height: 300
title: mp3
onClose: operation(){
content: BorderPanel {
center: TextArea {
text: "size: {f.fileSize/1000} kb\ntitle: {f.title}
\nalbum: {f.album}\nartist: {f.artist}\nyear: {f.year}"

Compiled library - 100kb


Your rating: None
Published at DZone with permission of its author, Sergey Surikov.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Thomas Mueller replied on Wed, 2008/02/27 - 11:39am

A bit simpler than JLayer is mp3transform at

It's only about 10 classes. 

(disclaimer: I wrote it, and it is based on JLayer)

Andres Almiray replied on Wed, 2008/02/27 - 12:05pm

I'm still waiting to see the WOW factor. Some shiny eye-catching controls would have been nice, I mean the example is really a regular Java class sans Swing (actually Swing driven by JavaFX).

Umberto Zappia replied on Wed, 2008/02/27 - 12:18pm

There are so many examples of what JavaFX can do right now, and they are pretty neat, simple and still in beta, I can't wait to see JavaFX in action @ JavaOne.

Great post.


Sergey Surikov replied on Wed, 2008/02/27 - 4:33pm in response to: Andres Almiray

[quote]Some shiny eye-catching controls would have been nice[/quote]

Look to chart controls from

isn't they nice?



Andres Almiray replied on Wed, 2008/02/27 - 5:13pm in response to: Sergey Surikov

Much better but nothing out of the ordinary (after all we can do that with Swing today). What I mean is if JavaFX is a great step into eye-catching UIs and ease-of-use I have yet to see *any* example that makes me shout "OMG I can't believe how easy is to do _that_ with JavaFX, I can't do that with Swing!".

Needless to say I find interesting your latest JavaFX postings but again I can do that with Swing today without breaking a sweat.

Carl Antaki replied on Wed, 2008/02/27 - 9:24pm

The last time I checked Javazoom which has not changed since, it didn't play some of the MP3s I have. I mean Sun should probably need to build their own or improve Javazoom instead of using this library that doesn't work all the time.

Java has unfortunately lost the game on the browser RIA as Flash is the standard. Sun cannot match Adobe's tools. The new Java plugin that will be released should have been done years ago, Flash wouldn't have existed maybe. Don't get me wrong I love Swing but I really didn't like JavaFX syntax. Also I've bashed over and over over having context menus (Cut Copy Paste, Undo and Redo) in text components but Sun doesn't seem to understand that it kills accessibility.


Brian Matzon replied on Thu, 2008/02/28 - 2:56am

Just dont use mp3! ogg vorbis is free, whereas mp3 requires a license agreement:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.