我使用下面的代码从我的设备上的服务器下载视频文件,但下载1.5 MB
大小的文件需要30秒以上。有没有办法加快这个下载过程?
我们可以将整个视频文件分成块并同时下载吗?
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:videoURL]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:videoURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"m.mp4"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:outputPath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", outputPath);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error downloading file");
}];
[httpClient enqueueHTTPRequestOperation:operation];