java播放MP3

时间:2021-04-24 05:01:50
【文件属性】:

文件名称:java播放MP3

文件大小:545KB

文件格式:ZIP

更新时间:2021-04-24 05:01:50

mp3

这是一个播放mp3的java程序,里面自带jdk package testes; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import javazoom.jl.decoder.JavaLayerException; import javazoom.jl.player.Player; public class MusicTest { private Player player; private String file = "D:/csd/Maroon.mp3"; public MusicTest() throws LineUnavailableException, UnsupportedAudioFileException, IOException { } public void play() throws IOException, JavaLayerException { File music = new File(file); BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(music)); player = new Player(buffer); player.play(); } public static void main(String[] args) throws JavaLayerException { try { new MusicTest().play(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } } }


网友评论