Java enables us to create an mp3 player using only 3 lines of code. For this we will use JavaFx. Follwing is the procedure to create an mp3 player in javafx using only 3 lines of code.

1. Open Netbeans and create a new javaFX project.

2. Import the following libraries.



3. Type the following code in main function. But in file object, enter the address of song which you want to play, here I have added the address of song located in my PC.

File file =new File("C:\\Users\\Ahmed Ali\\Documents\\Music\\grapes_-_I_dunno.mp3");

Media song= new Media(file.toURI().toString());

MediaPlayer player =new MediaPlayer(song);;

4. Run the program and you will hear the song.!

5. That's all. This is the simplest mp3 player. Now you can improve it by adding stop, resume buttons and you can create a beautiful GUI for it so that it looks like a professional mp3 player. Good Luck!

Mp3 Player with GUI