简体   繁体   English

视频应用程序将.mp4保存到相机胶卷

[英]video app save .mp4 to camera roll

i have a vidoe app that all she does is to play a single .mp4 file. 我有一个vidoe应用程序,她所做的就是播放一个.mp4文件。 i want to save that file to camera roll in the iphone it will be played. 我想将该文件保存到iPhone的相机胶卷中,然后将其播放。 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
            }
        }];
    }
    }

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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM