亲宝软件园·资讯

展开

JavaSwing播放音乐 JavaSwing后台播放音乐mp3

Brandon.Lin 人气:0

本文为大家分享了用Java来播放mp3的具体代码,使用jl1.0.1.jar,供大家参考,具体内容如下

代码:

import java.io.BufferedInputStream;
import java.io.FileInputStream;
 
import javazoom.jl.player.Player;
 
/**
 * @author Brandon B. Lin
 * 2013-1-25
 */
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;
 
}

加载全部内容

相关教程
猜你喜欢
用户评论