如何下载视频并将其保存在ipad中。?

时间:2011-07-05 06:57:19

标签: iphone ipad ios-simulator

如何在iPad中下载视频。我有一个视频的URL,我需要将其下载并保存在我的iPad数据库中并离线使用。任何人都可以帮我解决问题吗?

我在代码上尝试此操作,但它无法保存文件。在此代码之后,我使用Media Player播放它。但它没有下载,所以我无法播放。

NSURL *url = // some-URL;
NSData *yourVedioFileData = [[NSData alloc] initWithContentsOfURL:[NSURLURLWithString:url]];

//Store the Data locally as Video File

NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourFilePath = [documentsDirectory stringByAppendingPathComponent:@"yourVideoName.mov"];
[yourVedioFileData writeToFile:yourFilePath atomically:YES];

1 个答案:

答案 0 :(得分:1)

NSString *imagelist = URL_NAME;

NSData *yourVideoFileData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imagelist]];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *yourFilePath = [documentsDirectory stringByAppendingPathComponent:@"YOUR_File_Name.mov"];

[yourVideoFileData writeToFile:yourFilePath atomically:YES];