Java实现播放Mp3的功能

这里需要导入一个jar包:jl1.0.1.jar

import java.io.BufferedInputStream;
import java.io.FileInputStream;

import javazoom.jl.player.Player;

public class MP3Player {
     
    private String filename;
    private Player player;

    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("D:\\CloudMusic\\英雄联盟 - Burning Bright  (Star Guardians - Login Screen).mp3");
        mp3.play(); 
    }
}

你可能感兴趣的:(java,java,mp3)