我一直在使用 AFnetworking 从远程服务器下载视频。它工作得很好,除了它将文件下载为数据而不是原始格式(在本例中为 mp4)。
有没有办法设置 AFnetworking 将文件下载为 mp4?在播放方面,每次播放视频时将数据文件转换回 mp4 似乎是浪费时间和资源。
我当前获取文件的代码如下:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[URL url]]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[URL title]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
URL.videolocal = @"YES";
[self saveToCoreData]; // video is not saved in core data, only a reference
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];