0

我有一个视频应用程序,她所做的就是播放单个 .mp4 文件。我想将该文件保存到将播放的 iphone 中的相机胶卷。我已经有了代码,但由于某种原因视频无法保存。

没有错误,似乎没有任何东西放错了位置,但仍然没有保存。我花了几个小时托盘来解决这个问题,但没有成功。如果有人可以帮我解决这个问题?请?请问漂亮吗?这是保存功能的代码...

- (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
            }
        }];
    }
    }
4

1 回答 1

1

抱歉,之前没有人回答过这个问题。如果您仍然需要帮助,这应该适合您:

- (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
    }
}
于 2013-05-08T19:53:49.563 回答