1

我想将下载的视频文件存储到图库中,但无法存储。请指导我如何解决它?

谢谢,

4

4 回答 4

2

试试这个,这对我有用

-(void)SaveVideoTOPhotoAlbum
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
        NSString *getImagePath = [basePath stringByAppendingPathComponent:videoName];
           printf(" \n\n\n-Video file == %s--\n\n\n",[getImagePath UTF8String]);
        UISaveVideoAtPathToSavedPhotosAlbum ( getImagePath,self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
    }

//

- (void) video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
    {
        NSLog(@"Finished saving video with error: %@", error);
        //kapil here ****
    }

宝贝,祝你好运

于 2013-08-27T06:37:18.807 回答
0

您可以使用UISaveVideoAtPathToSavedPhotosAlbum保存

解决方案

UISaveVideoAtPathToSavedPhotosAlbum(yourVideoPath, nil, nil, nil);

要获得视频路径,您必须将其保存在任何地方。您可以保存到目标路径。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString * yourVideoPath = [basePath stringByAppendingPathComponent:@"video.mov"];

[yourVideoData writeToFile:yourFilePath atomically:YES];
于 2013-08-27T06:31:33.120 回答
0

你可以试试这个链接吗??

这会将指定路径的电影添加到用户的相机胶卷相册。

void UISaveVideoAtPathToSavedPhotosAlbum (
   NSString  *videoPath,
   id        completionTarget,
   SEL       completionSelector,
   void      *contextInfo
);

您将在我指定的上述链接中找到进一步的指导

更有用的链接是这个

希望能帮助到你 ..

于 2013-08-27T06:32:47.377 回答
0

试试这个...

NSURL *videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"Your Video Url"]];

dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(q, ^{

NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];

dispatch_async(dispatch_get_main_queue(), ^{

    // Write it to cache directory
    NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file.mov"];
    [videoData writeToFile:videoPath atomically:YES];

    // After that use this path to save it to PhotoLibrary
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath] completionBlock:^(NSURL *assetURL, NSError *error)
     {
         if (error)
         {
             NSLog("Error");
         }
         else
         {
             NSLog("Success");
         }

        }];
    });
});
于 2016-03-11T11:36:10.483 回答