Pin It

How to Play an MP3 File in Java ?

In order to play Mp3 files in Java , you need to download  jl1.0.jar from the website  javazoom.net. After downloading put the jar into Eclipse or Netbeans buildpath and execute below code.


Program to demonstrate how to play Mp3 files in Java

package com.hubberspot.example;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javazoom.jl.player.Player;


public class Mp3Player {
   
    private String filename;
    private Player player; 


    public Mp3Player(String filename) {
 this.filename = filename;
    }


    public void play() {
 try {   
            BufferedInputStream buffer = new BufferedInputStream(
    new FileInputStream(filename));
     player = new Player(buffer);
     player.play();
 }
 catch (Exception e) {

     System.out.println(e);
 }

    }

    public static void main(String[] args) {
 Mp3Player mp3 = new Mp3Player("song.mp3");
 mp3.play();

    }

}




Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot