Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implement Java fm radio

Tags:

java

swing

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?

like image 440
user414967 Avatar asked Jun 09 '26 06:06

user414967


2 Answers

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.

like image 168
Mikle Garin Avatar answered Jun 11 '26 22:06

Mikle Garin


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.

like image 39
AurA Avatar answered Jun 11 '26 22:06

AurA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!