【发布时间】:2016-02-09 06:21:02
【问题描述】:
我已将 .mp4 文件从服务器下载到文档目录并调用 writeVideoAtPathToSavedPhotosAlbum 方法保存到画廊,但它也不工作。它抛出资产 url nil。任何人都可以帮助我解决这个问题
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"test.mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:path];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
NSLog(@"Moview URL:%@",movieURL);
NSURL *url = [movieURL copy];
[library writeVideoAtPathToSavedPhotosAlbum:url
completionBlock:^(NSURL *assetURL, NSError *error)
{
NSLog(@"Asset Url:%@",assetURL);
if(!error) {
NSLog(@"\t ! Error");
NSLog(@"\t Error: %@", [error localizedDescription]);
NSLog(@"\t Error code %d", [error code]);
}
if(error != nil) {
NSLog(@"\t ERROR != NIL");
NSLog(@"\t Error - Image Failed To Save With Error: %@", [error localizedDescription]);
NSLog(@"\t Error code %d", [error code]);
}
if(error == nil) {
NSLog(@"\t ERROR == NIL");
}
}];
【问题讨论】:
-
这一行的日志是什么:- NSLog(@"Moview URL:%@",movieURL);?在这里评论
-
这一行有什么用:- NSURL *url = [movieURL copy];
-
url 为文档目录中视频位置的asset url
-
您是否在变量“URL”中获得任何值,然后记录它?
-
URL 值在那里 file:///var/mobile/Containers/Data/Application/E0B3785E-D991-4FE3-A67A-C49A3D2DF032/Documents/test.mp4 但在 writeVideoAtPathToSavedPhotosAlbum 中,资产 url 是无。它也不会保存到画廊中
标签: ios objective-c media assets