Over a million developers have joined DZone.
Silver Partner

Playing MP3 Files in JavaFX

· Java Zone

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 http://www.javazoom.net/javalayer/javalayer.html.


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

jmp3.zip - 100kb



{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}