2013-07-22 181 views
2

如何将文档目录中的视频保存到iOS中的图库,在这里我从服务器下载视频并保存在文档目录中,现在我想将它移动到图库。如何将视频从文档目录保存到图库?

+0

[UISaveVideoAtPathToSavedPhotosAlbum](https://developer.apple.com/library/ios/documentation/UIKit/Reference /UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UISaveVideoAtPathToSavedPhotosAlbum)和(http://stackoverflow.com/q/9991332/1059705) – Bala

回答

3
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil); 

可以通过SOURCEPATH作为

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 

附加您的文件名或路径来获得源路径。

NSString *sourcePath = [documentsDirectory stringByAppendingPathComponent:@"youVideo.mp4"]; 
+0

如果我使用这两行代码,它会工作NSString * sourcePath = [exportURL path]; UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil); – user2402997

+0

你必须添加源码路径作为Nitin描述在下面的anser ..看到编辑 –

4

首先,你需要得到像特定的视频路径或文件目录: -

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"youVideo.mp4"]; 
NSURL *movieURL = [NSURL fileURLWithPath:path]; 


ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease]; 
[library writeVideoAtPathToSavedPhotosAlbum:movieURL 
          completionBlock:^(NSURL *assetURL, NSError *error){/*notify of completion*/}]; 
+0

这不适合我 –

相关问题