Reputation: 1
i have a vidoe app that all she does is to play a single .mp4 file. i want to save that file to camera roll in the iphone it will be played. i already have the code but for some reason the video is not able to save.
no errors, nothing seems to be misplaced but still doesnt save. i spend hours traying to solve that problem but no sucsses. if someone can help me figure that out? please? pretty please? here is the code for the save function...
- (IBAction)save{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// don't forget to link to the AssetsLibrary framework
// and also #import <AssetsLibrary/AssetsLibrary.h>
NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:filePathURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:filePathURL completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
// TODO: error handling
} else {
// TODO: success handling
}
}];
}
}
Upvotes: 0
Views: 1836
Reputation: 383
Sorry no one has answered this earlier. If you still need help, this should work for you:
- (IBAction)save{
NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO];
UISaveVideoAtPathToSavedPhotosAlbum([filePathURL relativePath], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
- (void) video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (!error){
// Saved successfully
} else {
// Error saving
}
}
Upvotes: 1