问题
How to save video with my custom album . I found one link but it don't work Custom file manager
It gives the url value is null.
[VideoAlbumManager addVideoWithAssetURL:outputFileUrl toAlbumWithName:@"Video Maker"];//outputfileurl is my video url from document directory
Give any suggestion for this..
回答1:
You can use this link to save the video.. GitHub Link
Import this two files into your project.
- ALAssetsLibrary+CustomPhotoAlbum.h
- ALAssetsLibrary+CustomPhotoAlbum.m
Then in your save IBAction method write this lines..
if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputFilePath)){
NSURL *muyrl=[NSURL fileURLWithPath:outputFilePath];
[library saveVideo:muyrl toAlbum:albumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(@"Big error: %@", [error description]);
}
}];
Where.. outputfilepath is your videopath and if you have url then save it with URL name. library is ALAssetLibrary that define in .h file albumName is your Album name what do you want..I hope this will help you.
回答2:
-(void)SaveToalbum{
NSString *finalFileName=[NSString stringWithFormat:@"Documents/video.mov"];
NSString *videoOutputPath = [NSHomeDirectory()
stringByAppendingPathComponent:finalFileName];
NSString* webStringURL = [videoOutputPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url =[NSURL URLWithString:webStringURL];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:url])
{
NSURL *clipURl = url;
[library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error)
{
}];
}
}
You can try with it. It will be helpful for you. Just go through "http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/" link and download the sample project.
- Drag-drop two file
"ALAssetsLibrary+CustomPhotoAlbum.h"
and"ALAssetsLibrary+CustomPhotoAlbum.m"
into your project and add"AssetsLibrary.framework"
. Now you are ready for coding.Just go on yourViewController.h
Class and import the<AssetsLibrary/AssetsLibrary.h>
and"ALAssetsLibrary+CustomPhotoAlbum.h"
file.- Create a object for
ALAssetsLibrary
and write a block for saving the video file in custom album,just like this,
[ALAssetsLibraryObject addAssetURL:clipURl toAlbum:AlbumName withCompletionBlock:^(NSError *error)
{
if (error!=nil) {
NSLog(@"Big error: %@", [error description])
}
}];
来源:https://stackoverflow.com/questions/25645793/save-video-into-custom-album-ios