In addition to AurA answer...
You can use JLayer library to easily read and play most of internet radios.
That library is also cross-platform and, additionally, allows you to play any mp3 file.
Here is a small stream player example:
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
public class RadioConnector
{
public static void main ( String[] args )
{
try
{
playRadioStream ( "http://radio.flex.ru:8000/radionami" );
}
catch ( IOException e )
{
e.printStackTrace ();
}
catch ( JavaLayerException e )
{
e.printStackTrace ();
}
}
private static void playRadioStream ( String spec ) throws IOException, JavaLayerException
{
// Connection
URLConnection urlConnection = new URL ( spec ).openConnection ();
// If you have proxy
// Properties systemSettings = System.getProperties ();
// systemSettings.put ( "proxySet", true );
// systemSettings.put ( "http.proxyHost", "host" );
// systemSettings.put ( "http.proxyPort", "port" );
// If you have proxy auth
// BASE64Encoder encoder = new BASE64Encoder ();
// String encoded = encoder.encode ( ( "login:pass" ).getBytes () );
// urlConnection.setRequestProperty ( "Proxy-Authorization", "Basic " + encoded );
// Connecting
urlConnection.connect ();
// Playing
Player player = new Player ( urlConnection.getInputStream () );
player.play ();
}
}
Note that playRadioStream method will handle the thread its called from until something happes (for example connection to radio server breaks or you stop the stream).
P.S. Yes, i have included working radio URL into the example - you can try launching it and your computer will start playing the radio stream.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…