How to download a video from url with chunks in both server and client end.
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
// Specify what portion of file to download.
connection.setRequestProperty("Range",
"bytes=" + downloaded + "-");
// Connect to server.
connection.connect();
// Make sure response code is in the 200 range.
if (connection.getResponseCode() / 100 != 2) {
error();
}
// Check for valid content length.
int contentLength = connection.getContentLength();
if (contentLength < 1) {
error();
}
/* Set the size for this download if it
hasn't been already set. */
if (size == -1) {
size = contentLength;
stateChanged();
}
// Open file and seek to the end of it.
File f = new File("/sdcard/Sample");
if(f.exists())
{
}else
{
f.mkdir();
}
file = new RandomAccessFile(f.getAbsolutePath()+"/"+getFileName(url), "rw");
file.seek(downloaded);
stream = connection.getInputStream();
here i want to download a file like a chunks ... if the chunks coming from server and my client end i need to download and merge that complete video file