java achieve Snake Case Background music

1. Import jar package

 

2. The use of threads to control playback, or else form finished playing the song would have to wait to appear.

//主背景音乐。
class MusicPlayer extends Thread{
Player player;
String music;
public MusicPlayer(String file) {

this.music = file;
}
public void run() {
try {

play();
} catch (FileNotFoundException | JavaLayerException e) {
e.printStackTrace();
}
}
public void play() throws FileNotFoundException, JavaLayerException {
BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(music));
player = new Player(buffer);
player.play();
}
}

 

 

// main background music is turned on.
Music = new new MusicPlayer MusicPlayer ( "\\ musics 02.mp3");
music.start ();

Guess you like

Origin www.cnblogs.com/insist-bin/p/11098446.html