Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700
Accepted Solution

Downlaod video file in chunks not working

HI ,

 

I have to downaload  videos from and server .I am using this article to get the video file downlaoded 

 

http://supportforums.blackberry.com/t5/Java-Development/Download-large-files-using-the-BlackBerry-Mo...

 

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_CONTENT_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

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Downlaod video file in chunks not working

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"

Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: Downlaod video file in chunks not working

 

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.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Downlaod video file in chunks not working

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?

Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: Downlaod video file in chunks not working

[ Edited ]

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

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Downlaod video file in chunks not working

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. 

Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: Downlaod video file in chunks not working

[ Edited ]

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.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Downlaod video file in chunks not working

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.

Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: Downlaod video file in chunks not working

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

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Downlaod video file in chunks not working

"Chunk Downloaded: 64 Bytes"

Did I not suggest 64K bytea?