0

I am trying to download specific bytes of a file from google drive. When I set bytes=0-1000, it works fine. When I am specifying a particular range of bytes (as shown below), the size of the video getting downloaded is correct but, I couldn't play the video.

HttpRequest httpRequestGet = drive.getRequestFactory().buildGetRequest(new GenericUrl(url.toString()));
httpRequestGet.getHeaders().setRange("bytes=" + 10000 + "-" + 200000);

Am I missing something? Thanks in advance.

Heen Shaik
  • 1
  • 1
  • 1
  • Are you sure your video format support being streamed? Also, even if it do, you will probably need the headers that are at the beginning of the file to properly play it – litelite Aug 21 '17 at 15:51
  • Yes, when I specify bytes=0-(any value within the size) the file is correctly being downloaded and I can play the video. – Heen Shaik Aug 21 '17 at 18:09
  • Thats because when you download from byte 0 the headers are included. Your video is probably invalid if the headers are not present (as it might contain crucial information about the video). And that format is probably streamable and is not bothered by the fact that the end is missing. – litelite Aug 21 '17 at 18:11
  • Thank you so much I understood now. Could you please tell me how can I correct it? – Heen Shaik Aug 21 '17 at 18:14
  • @litelite I am using getHeaders() before calling setRange(..). How come the header information is lost? – Heen Shaik Aug 22 '17 at 07:29
  • It's because `getHeaders()` is getting the headers of the HTTP request. Not the one of the file. Streaming a video file is much more complicated than that. https://stackoverflow.com/questions/2308181/how-can-i-code-a-server-client-video-and-audio-streaming-application – litelite Aug 22 '17 at 12:27

1 Answers1

1

It could be probably because by specifying a byte range further down in the file you are skipping the entire header of the file, which results in just a garbled block of data.

Partha Das
  • 170
  • 2
  • 11
  • But, how come the size of the file is correct? Could you please elaborate?Could you please provide any sample code so that I could get the output? – Heen Shaik Aug 21 '17 at 18:08