Click to See Complete Forum and Search --> : Linking to online radio


ragheb.khaseeb
02-14-2010, 02:25 PM
i need some help to connect to online radio via flex

marvin steve
02-19-2010, 12:38 AM
hi there

i too want he details of steps to connect the online radio,pls anyone assist me to do this

ragheb.khaseeb
02-19-2010, 05:18 AM
Hi Steve

I made some progress in this topic

At server side i used java to connect to the online radio and to write the output to the client side(flash side) but it needs to enhance buffer at client side

java side

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fileName = "test.mp3";
response.setContentType("audio/mpeg");

response.addHeader("Content-Disposition", "attachment; filename="
+ fileName);
try {
URL url = new URL("http://212.33.100.50:8008/");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(stream);
FileOutputStream fos = new FileOutputStream("test.mp3");
ServletOutputStream oStream = response.getOutputStream();

byte []buffer = new byte [1*1024];
long i = 0;
int in;
while((in = stream.read()) != -1){
stream.read(buffer);
oStream.write(buffer);
}
} catch (Exception e) {
// TODO: handle exception
}
}


flash side

//url of the above servlet
var servletURL:String = ""http://localhost:8080/TestRadio/Ajyal";

var snd:Sound = new Sound();
var req:URLRequest = new URLRequest(servletURL);
var context:SoundLoaderContext = new SoundLoaderContext(0, false);

snd.load(req, context);
snd.play();

snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);