Sadly MP3 support within Java is lacking. I am developing an app that needs to receive chunks of MP3 and play them. I was using Jlayer MP3 library like this:
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();
}
But my problem is that I have only chunks of the full MP3 file, and I need to play them as they arrive. Is there any better alternative?
Edit
Found an interesting similar question: MP3 won't stream with JMF Also: Decoding MP3 files with JLayer