Here in the minecraft launcher nadybal. Going through this program where to write the name of the file that will be played. Let the file name be electro.mp3.

package net.minecraft; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import javazoom.jl.player.Player; public class MusPlay { private String filename; private Player player; // constructor that takes the name of an MP3 file public MusPlay(String filename) { this.filename = filename; } public void close() { if (player != null) player.close(); } // play the MP3 file to the sound card public void play() { try { InputStream is=getClass().getResourceAsStream(setting.iMusicname); BufferedInputStream bis = new BufferedInputStream(is); player = new Player(is); } catch (Exception e) { System.out.println("Problem playing file " + filename); System.out.println(e); } // run in new thread to play in background new Thread() { public void run() { try { player.play(); } catch (Exception e) { System.out.println(e); } } }.start(); } 

}

    1 answer 1

    In the constructor, pass the path to the file, and then call the play(); method play();