08-19-2012 02:42 AM
HI ,
I have to downaload videos from and server .I am using this article to get the video file downlaoded
But its not working for me as I am unable to calculate the excar byte range too request as chunk and stuck in a loop .
while (true) {
log("Opening Chunk: " + chunkIndex);
conn = (HttpConnection) getHttpConnection(currentFile);
conn.setRequestMethod( HttpConnection.POST );
conn.setRequestProperty("x-rim-transcode-content", "none");
rangeStart = chunkIndex * chunksize;
rangeEnd = rangeStart + chunksize - 1;
log("Requesting Range: " + rangeStart + "-" + rangeEnd);
conn.setRequestProperty("Range", "bytes=" + rangeStart + "-" + rangeEnd);
log("Http.HEADER_CONTENT_LENGTH" + conn.getHeaderField(HttpProtocolConstants.HEADER_C ONTENT_LENGTH));
int responseCode = conn.getResponseCode();
if (responseCode != 200 && responseCode != 206)
{
log("Response Code = " + conn.getResponseCode());
break;
}
in = conn.openInputStream();
int length = -1;
byte[] readBlock = new byte[1024];
int fileSize = 0;
while ((length = in.read(readBlock)) != -1) {
out.write(readBlock, 0, length);
fileSize += length;
Thread.yield(); // Try not to get cut off
}
totalSize += fileSize;
log("Chunk Downloaded: " + fileSize + " Bytes");
chunkIndex++; // index (range) increase
in.close();
conn.close();
in = null;
conn = null;
}
log("Full file downloaded: " + totalSize + " Bytes");
out.close();
file.close();
log("Wrote file to local storage");
Above is the code I am using ,kindly any one help me out what I am missing
thanks in advance for your help
Solved! Go to Solution.
08-19-2012 06:15 AM
Can you explain what you mean by this in a bit more detail please? I am not clear on what your problem actually is.
"But its not working for me as I am unable to calculate the excar byte range too request as chunk and stuck in a loop"
08-19-2012 06:29 AM
It is so that my video dowlaoding nerver comes to an end, the below lines never get exceuted ,
log("Full file downloaded: " + totalSize + " Bytes");
out.close();
file.close();
log("Wrote file to local storage");
my get data range keeps on going , (i get only response code 206 ), I had chnage the chunks size from 64 , 256 , 512 , 1024 but still the same right now em testing for a video file of size 400 Kb.
Also when I check in file 0 bytes get written.
08-19-2012 06:36 AM
I would recommend that you try a chunk size of 64 K, so you should get the file down in about 7 chunks. Does that work?
08-19-2012 06:54 AM - edited 08-19-2012 06:55 AM
I tried that chunk size too but issue is thr , I don't know why but the loops keep on running
I am working on OS 6 using 9780 bold simulator
08-19-2012 07:29 AM
And what do you see in the log?
I'm specifically looking for thenoutput from these log statements:
log("Requesting Range: " + rangeStart + "-" + rangeEnd);
and
log("Response Code = " + conn.getResponseCode());
Are you downloading a file or a stream? As a clue, what is the "filename" you have defined in currentFile? This code is intedned for files, not streams.
08-19-2012 09:05 AM - edited 08-19-2012 09:21 AM
if I choose chunk size 64
log("Requesting Range: " + rangeStart + "-" + rangeEnd);
it prints 0-63 at start and than keep adding on
log("Response Code = " + conn.getResponseCode());
206 get print each time
Yes I am downlaoding a video file with the extension .3GP which I had uploaded a while agon on server.
08-19-2012 11:21 AM
I suggested using 64 K, that is 65536 bytes. Have you tried something around that size.
Can you try this isze and paste in the first 10 lines you get with Requesting Range.
08-20-2012 09:34 AM
here is the log as ua sked for
log -> Opening Chunk: 0 log -> Response from server is OK for ping URL withconnection UID log -> Requesting Range: 0-63 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 1 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 64-127 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 2 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 128-191 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 192-255 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 4 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 5 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 320-383 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 6 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 384-447 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 7 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 448-511 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 8 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 512-575 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 9 BbiAuth:ERR:No BBI Auth Token Request Engine available log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 576-639 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 10 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 640-703 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 11 log -> Response from server is OK for ping URL for https suffix legth greater than 0 log -> Requesting Range: 704-767 log -> Http.HEADER_CONTENT_LENGTH64 log -> Chunk Downloaded: 64 Bytes log -> Opening Chunk: 12
08-20-2012 09:40 AM
"Chunk Downloaded: 64 Bytes"
Did I not suggest 64K bytea?