遗憾的是,Java对MP3的支持不足。我正在开发一个需要接收MP3块并播放它们的应用程序。我以前使用类似这样的Jlayer MP3库:
import javazoom.jl.player.Player;
public class MP3 {
private String filename;
private Player player;
// constructor that takes the name of an MP3 file
public MP3(String filename) {
this.filename = filename;
}
public void close() { if (player != null) player.close(); }
// play the MP3 file to the sound card
public void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
}
catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
player.play();
}
但我的问题是我只有完整MP3文件的一部分,并且需要在它们到达时播放它们。是否有更好的替代方案?
编辑
发现一个有趣的类似问题:JMF流无法播放MP3 还有:使用JLayer解码MP3文件