In this tutorial, I will demonstrate you how to write a Java Source code to run an mp3 file. I will use Eclipse IDE for creating this project.
Step 1: Create "PlayMp3" project in Eclipse
Step 2: Import jl1.0.jar file to the Eclipse project. (To learn how to correctly add .Jar file to Eclipse project, please follow this article)
Download jl1.0.jar
Step 3: Write the following code in PlayMp3.java file
Step 4: Import Mp3 file to the project
Step 5: Run the project and you can see the output
As an improvement, try to develop a small MP3 player which contains start, pause and stop buttons.
Step 1: Create "PlayMp3" project in Eclipse
Step 2: Import jl1.0.jar file to the Eclipse project. (To learn how to correctly add .Jar file to Eclipse project, please follow this article)
Download jl1.0.jar
Step 3: Write the following code in PlayMp3.java file
//Copyrighted geekdecoders.blogspot.com import javazoom.jl.player.Player; import java.io.FileInputStream; public class PlayMp3 { public static void main(String[]args) { try { String x = new java.io.File(".").getAbsolutePath(); FileInputStream mp3_file = new FileInputStream(x+"\\Test123.mp3"); Player mp3=new Player(mp3_file); System.out.println(x); mp3.play(); } catch(Exception e) { System.out.println(e); } } }
Step 4: Import Mp3 file to the project
Step 5: Run the project and you can see the output
As an improvement, try to develop a small MP3 player which contains start, pause and stop buttons.
Very nice article,keep sharing it.
ReplyDeleteThank you.
Power BI Course