3
如何在服务器端和客户端使用块从URL下载视频。如何在服务器端和客户端使用块从URL下载视频
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();
在这里,我想下载像块文件......如果从服务器传来的数据块和我的客户端我需要下载和合并是完整的视频文件