1

我正在尝试使用glimpse来记录 UIView。它成功地将其保存到应用程序的文档文件夹中,但是我还需要将其保存到用户的相机胶卷中。它没有保存到相机胶卷,我收到一条警告,允许该应用访问我的相机胶卷,但它没有保存在任何相册中。

我已经尝试了相当数量的代码,包括:

[self.glimpse startRecordingView:self.view onCompletion:^(NSURL *fileOuputURL) {
        NSLog(@"DONE WITH OUTPUT: %@", fileOuputURL.absoluteString);


      UISaveVideoAtPathToSavedPhotosAlbum(fileOuputURL.absoluteString,nil,nil,nil);





    }];

对此:

 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library writeVideoAtPathToSavedPhotosAlbum:fileOuputURL
                                    completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"hello");}];

日志打印,但它不会将视频保存到相机胶卷。

如果有人对我的这行不通有任何想法,请告诉我!谢谢!

4

2 回答 2

20

问题在于提供的视频路径。提供来自 url 的相对路径。

if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileUrl.relativePath) {
    UISaveVideoAtPathToSavedPhotosAlbum(fileUrl.relativePath, nil, nil, nil)
}

如果您添加了这个UIVideoAtPathIsCompatibleWithSavedPhotosAlbum检查编译器会向您显示该文件的问题。

于 2015-08-14T12:15:02.723 回答
4

问题是您的视频路径以 URL 形式给出,因此您必须检查您的 URL 路径是否可压缩以保存在视频中,如果您想将视频保存在 camara roll 中,则只需传递 URL 并遵循以下代码:

-(void)saveVideo:(NSString *)videoData withCallBack:(void(^)(id))callBack{
library = [[ALAssetsLibrary alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSData *yourVideoData=[NSData dataWithContentsOfURL:[NSURL URLWithString:videoData]];
    if (yourVideoData) {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"video.mp4"];


                 if([yourVideoData writeToFile:filePath atomically:YES])
                 {
                     NSURL *capturedVideoURL = [NSURL URLWithString:filePath];
                    //Here you can check video is compactible to store in gallary or not
                     if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:capturedVideoURL]) {
                         // request to save video in photo roll.
                         [library writeVideoAtPathToSavedPhotosAlbum:capturedVideoURL completionBlock:^(NSURL *assetURL, NSError *error) {
                             if (error) {
                                 callBack(@"error while saving video");
                                 NSLog(@"error while saving video");
                             } else{

                                     callBack(@"Video has been saved in to album successfully !!!");

                    }
                         }];
                     }
                }

    }
});


}
于 2017-11-11T06:56:18.557 回答