Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

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();

    }

}




 
© 2021 Learn Java by Examples Template by Hubberspot