我已将视频临时存储在 Documents 目录中。
这是示例视频路径:file:///var/mobile/Containers/Data/Application/C651A13F-8F7C-4FCB-A1D9-D6D4C5F512E7/Documents/mergeVideo.mov
我想将此视频保存在专辑目录中。为此,我必须将此文件 url 转换为资产 url。
我已经尝试了解决方法..但无济于事..有人可以指导..吗?
为了使这段代码工作,我必须将文件 url 转换为资产 url .. 怎么做?
我已经有了使用资产 url 保存视频的代码。这是我的代码:
-(void)save2cameraRoll{
NSString *albumName=@"album name";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {
NSLog(@"added album:%@", albumName);
}
failureBlock:^(NSError *error) {
NSLog(@"error adding album");
}];
__block ALAssetsGroup* groupToAddTo;
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumName]) {
NSLog(@"found album %@", albumName);
groupToAddTo = group;
}
}
failureBlock:^(NSError* error) {
NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
}];
NSURL *fileURL = videoInputUrl;
[library assetForURL:fileURL
resultBlock:^(ALAsset *asset) {
// assign the photo to the album
[groupToAddTo addAsset:asset];
NSLog(@"Added %@ to %@", [[asset defaultRepresentation] filename], albumName);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Video Saved to HubRamped Album." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil];
[alert show];
}
failureBlock:^(NSError* error) {
NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
}];
}