- 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 main(String[] args) {
- MP3Player mp3 = new MP3Player("陈瑞 - 白狐.mp3");
- mp3.play();
- }
- private String filename;
- private Player player;
- }
- //该片段来自于http://www.codesnippet.cn/detail/090520149477.html
来源: http://www.codesnippet.cn/detail/090520149477.html