/**
*
*/
package common;
/**
* @author zhengweiwei
* @date 2014年9月17日
*/
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class MP3Player {
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 play(String filename,int times) {
try {
for (int i = 0; i < times; i++) {
BufferedInputStream buffer = new BufferedInputStream(
new FileInputStream(filename));
Player player = new Player(buffer);
player.play();
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws InterruptedException {
// MP3Player mp3 = new MP3Player("10s.mp3");
// for (int i = 0; i < 6; i++) {
// mp3.play();
//// Thread.sleep(500);
// }
play("倍儿爽.mp3", 5);
}
private String filename;
private Player player;
}