can any one tell me how to implement a standalone java client for playing FM radio. I searched over the net could not find anything useful. What are the all the API we need to implement and once the implementation is over, how to test it?
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.
There are many Radio websites that you can access using Webservices API's
I am posting the link of the most popular radio api online.
http://www.last.fm/api/radio
Using Java Web Services you can integrate with your application easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With