java 播放MP3音频

public static 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("C:\\Users\\Administrator\\Music\\毛不易 - 一纸情书.mp3");
    mp3.play();

}

需导入jlayer.jar;

maven导入jlayer.jar版本信息:

<dependency>
    <groupId>javazoomgroupId>
    <artifactId>jlayerartifactId>
    <version>1.0.1version>
dependency>

你可能感兴趣的:(java 播放MP3音频)