I'm writing a small app to play a shoutcast stream, and I am using javazoom.jl.player.Player to do this. Here is my code:
package music;
import java.io.InputStream;
import java.net.URL;
import javazoom.jl.player.Player;
class audiostream extends Thread {
private Player mediafilePlayer;
private volatile boolean shouldPlay = true;
@Override
public void run() {
while (true) {
if (shouldPlay) {
player();
}
}
}
public void player() {
try {
URL mediafile = new URL("http://hi1.streamingsoundtracks.com:8000/;");
InputStream stream = mediafile.openStream();
mediafilePlayer = new Player(stream);
mediafilePlayer.play();
} catch (Exception e) {
System.out.println(e);
}
}
public void pause() {
shouldPlay = false;
mediafilePlayer.close();
}
public void play() {
shouldPlay = true;
}
}
This works perfectly fine on my Mac and I can hear the stream. However on Windows when I try to run this I get the error "java.io.IOException: Invalid Http response". I believe this is because SHOUTcast returns icy 200 ok headers wherein something on Windows must want it to return http headers. I can't seem to find how to make it accept these different headers on windows using javazoom Player.
I ended up solving this issue by using BasicPlayerListener instead. I replaced the code in my question with the following: