Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Playing MP3 Files in JavaFX

DZone's Guide to

Playing MP3 Files in JavaFX

· Java Zone ·
Free Resource

Atomist automates your software deliver experience. It's how modern teams deliver modern software.

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.

Source

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() {
f.play(this);
}
};
f.play(doneCather);

Frame {
visible: true
screenx: 50
screeny: 100
width: 300
height: 300
title: mp3
onClose: operation(){
MP3Player.stop();
}
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

 

Get the open source Atomist Software Delivery Machine and start automating your delivery right there on your own laptop, today!

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}