How to Play MP3 Music in Java

0
127

This tutorial entitled “How to Play MP3 Music using Java ” will help you on how to create an MP3 Player in Java using Nebeans IDE.

Before you proceed, please search and download the “JLayer” Library from any search engine. This library is use for playing MP3 music as decoder. Please follow all the steps to complete this tutorial.

How to Play MP3 in Java Steps

  1. Add or Create a new JFrame Form inside your project.

2. Design your JFrame just like the image below.

3. Insert your new download library inside your project.

4. Add an MP3 music inside your source package. We will use the MP3 to our player.

5. Above your class, insert the following code below to access the required library for music player.

  1. import java.io.*;
  2. import javazoom.jl.decoder.JavaLayerException;
  3. import javazoom.jl.player.*;

6. Double click your button and insert the codes below.

  1. try{
  2. File file = new File("Jonas Blue - By Your Side ft. RAYE.mp3");
  3. try{
  4.  
  5. Player player = new Player(bis);
  6. player.play();
  7.  
  8. }catch(Exception e){
  9. System.out.println(e.getMessage());
  10. }
  11.  
  12. }catch(Exception e){
  13. System.out.println(e.getMessage());
  14. }

7. Run your program and after hitting play button, the music will start to play.

Play MP3 Music using Java Final Output

This is the basic example of playing MP3 music using Java. This music player can only play a specified music. You can also play much music in one button event but it needs more time and coding technique. Just follow my new tutorials about playing music.

Facebook Comments
(Visited 135 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here