02-17-2009 11:12 PM - edited 02-17-2009 11:48 PM
Hi all,
I'm currently developing an audio streaming software application. It works by first authenticating with the audio website's authentication API. Then after receiving the session information I can request for each individual audio files. Now the trick is that the url to each of the audio file is to be only requested/accessed once only, after the first access, the ticket is expired immediatelly, and then one can only access other files within the same session.
What I'm trying to do here is to first download and buffer each of the audio file, given the valid urls. I am using tcp connection here because the audio files can be quite large(3-5 megs). (by including ";deviceside=true" in url) The problem comes when I change the connection from ready state to open state by either opening the input stream or getting the response code. The piece of code I used is:
String location = url+";deviceside=true";
HttpConnection s = (HttpConnection) Connector.open(location);
System.out.println("Response Code: "+s.getResponseCode());
System.out.println("Response Message: "+s.getResponseMessage());
long length = s.getLength();
InputStream in = s.openInputStream(); //open stream
byte[] data = new byte[256];
DataBuffer db = new DataBuffer();
int chunk = 0;
while (-1 != (chunk = in.read(data))) {
db.write(data, 0, chunk);
}
in.close();
s.close();
data = db.getArray();
// data is always empty for some reason
The response code I get is always 302 "Found", but when i open the input stream, the stream is empty. I have tried copying the individual url's for each audio file and then paste into my firefox, the files can be downloaded without a problem. The audio file would also stream fine from File>openURL in Windows Media Player. The url of the individual audio file is of the format "http://play.audiowebsite.com/user/df98sdfdf98sdfdf
How can I download these files from my application in BlackBerry. I have been trying to solve this problem for the past 5 days, and have made very little progress. I've searched every corner of this forum. This is my last resort. All helps are appreciated.
I'm using JDE4.7 and 8820 simulator
Solved! Go to Solution.
02-18-2009 06:52 AM - edited 02-18-2009 06:53 AM
As I recall most of the really good media tools only run on linux ( these are largely thought of
as hacking tools ). This problem however is probably straight http.
If you are stuck on windoze, get cygwin and use things like wget to test your server.
Or, go to ietf.org and find out what a 302 response is supposed to mean. Note this gets complicated
when some wireless sites do clever things like respond with cookies too etc.
In this case,
$ wget -O ~/xxx -S -v "http://play.audiosite.com/user/df98sdfdf98sdfdf98s
sdf1234.mp3"
--06:58:00-- http://play.audiosite.com/user/df98sdfdf98sdfdf98s
3
=> `/xxx'
Resolving play.audiosite.com... 63.119.44.197
Connecting to play.audiosite.com[63.119.44.197]:80... connected.
HTTP request sent, awaiting response...
1 HTTP/1.1 302 Found
2 Date: Wed, 18 Feb 2009 11:51:07 GMT
3 Server: Apache/2.2.3 (CentOS)
4 Set-Cookie: COOKIE=10.5.16.253.1234957867765295; path=/
5 Location: http://play.audiosite.com/
6 Content-Length: 64
7 Vary: Accept-Encoding,User-Agent
8 Cartoon: aalander3
9 Connection: close
10 Content-Type: text/html; charset=UTF-8
Location: http://play.audiosite.com/ [following]
--06:58:01-- http://play.audiosite.com/
=> `/r/xxx'
Connecting to play.audiosite.com[63.119.44.197]:80... connected.
HTTP request sent, awaiting response...
1 HTTP/1.1 200 OK
2 Date: Wed, 18 Feb 2009 11:50:52 GMT
3 Server: Apache/2.2.3 (CentOS)
4 Vary: Accept-Encoding,User-Agent
5 Cartoon: aalander5
6 Connection: close
7 Content-Type: text/html; charset=UTF-8
[ <=> ] 27,674 --.--K/s
06:58:01 (263.92 MB/s) - `/ho/xxx' saved [27674]
$
02-18-2009 08:21 PM
Thanks, the problem is solved.
I tried your approach using wget, and saw the response header, which had the new(redirected)link. Then I searched the forum again, and saw Mark's post in http://supportforums.blackberry.com/rim/board/mess
I then used HttpConnection.getHeaderField("Location") to get the correct link.
It's such a relief to have this problem solved.
02-19-2009 07:47 AM
02-19-2009 11:01 AM