MP3 Streaming over HTTP
Hi,
I磎 trying to connect to a Shoutcast server to play MP3 audio. I got the following fault when trying to open an HttpConnection:
"response does not start with HTTP it starts with: ICY"
The source code used looks like this:
============================================
HttpConnection conn = (HttpConnection) Connector.open("http://64.236.34.196/stream/1074");
Then I tried to open a socket connection as bellow:
======================================
SocketConnection conn = (SocketConnection) Connector.open("socket://64.236.34.196:80");
String get = "GET /stream/1074 HTTP/1.1";
DataOutputStream os = conn.openDataOutputStream();
os.writeUTF(get);
InputStream is = conn.openInputStream();
...
But then I got the following error: java.lang.SecurityException: Target port denied to untrusted applications
Could someone help me to find out what is going on?
Thanks a lot!
[976 byte] By [
fredgona] at [2007-10-2 20:20:04]

I guess you'll need to sign your midlet to make it able to connect to sockets directly.Secondly, writeUTF should not be used for this. It will not send a correct GET request to the shoutcast server.
Hi,
Ok, I managed to sign the midlet and connect to port 80. I also changed the writeUTF by writeChars (i磎 following an example from http://www.samspublishing.com/articles/article.asp?p=131116&seqNum=5&rl=1 ).
Anyway, now I got a new fault, when I try to read from the socket I don磘 receive any answer, and, after a while the connection is released with the following fault: "java.io.IOException: error 10054 during TCP read"
Not sure if I磎 not receiving any answer or if the midlet is not reading it properly...Any guess about that?
Thanks a lot!
By the way, here is the code I磎 trying to run now:
=======================================
SocketConnection conn = (SocketConnection) Connector.open("socket://64.236.34.196:80");
DataInputStream is = conn.openDataInputStream();
DataOutputStream os = conn.openDataOutputStream();
os.writeChars("GET /stream/1074 HTTP/1.0\r\nUser-Agent: WinampMPEG5.21\r\nAccept: */*\r\n\r\n"); //<-- not sure if I realy need the \r\n and parameters...
os.flush();
int inputChar;
while(true){
System.out.println("Reading data");
inputChar = is.read();
System.out.println("Data received: "+inputChar); //<-- is never printed
if(inputChar == -1)
break;
buf.append((char)inputChar);
}
According to http://www.pobox.co.uk/support/modules.php?name=News&file=article&sid=27 the error is socket close from the server side. Might be because you send the wrong stuff...
But if you stuff your parameters into telnet, it looks like it should work just fine.
The \r\n's are correct. What you might try is http 1.1. Also send the host parameter ("host: 64.236.34.196"). Another thing might be to use write ( "GET ....".getBytes()) and not writeChars. What you have should work, but you never know...
Hi,
I just develop Mobile Radio project in shoutcast.
Hope that there are some useful for you in the follow code :
(finished testing and OK in Nokia N73)
..........
out.write("GET / HTTP/1.1\r\n Accept: */*\r\n icy-metadata:1\r\n Connection:close\r\n\r\n".getBytes());
out.flush();
................
InputStream in=...........;
int sign=0xFF;
buf= new ByteArrayOutputStream();
while(true){
bt=in.read();
if(bt==sign&&in.read()==0xFB){
buf.write(0xFF);
buf.write(0xFB);
System.out.println();
break;
}
}
// get some mp3 data from shoutcast inputstream;
while((bt=in.read())!=-1){
buf.write(bt);
if(buf.size()>1024)break;
}
InputStream is = new ByteArrayInputStream(buf.toByteArray());
String type ="audio/mpeg"
log("create player ");
player = createPlayer(is, type);
player.addPlayerListener(this);
log("before start player");
player.realize();
// player.prefetch();
player.start();
Hi,
I was just searching for a Java Applciation for my phone - w800.
My question is, is there any application compiled in a JAR file, that can transmit mp3 music to a normal /basic bluetooth hands free device?
This facility is already supported in the mobile 6230i. Unfortunately, most of the new mobiles dont seem to have this facility and even if they have, it works with a STEREO bluetooth only.
Please can someone update me if the above mentions application is available, and if yes, where can i locate and download such file?
I have seen the java code written on the forum, but iam not a programmer so i have not understood how to compile and load it into my mobile handset.
Thanks in advance.
Regards
Brijesh (bshetty@techmahindra.com)