【问题标题】:video app save .mp4 to camera roll视频应用程序将 .mp4 保存到相机胶卷
【发布时间】:2013-03-21 20:08:06
【问题描述】:

我有一个视频应用程序,她所做的只是播放单个 .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
            }
        }];
    }
    }

【问题讨论】:

  • 拜托我没有任何想法,它让我的项目陷入困境。因此,如果有人可以帮助我,我将不胜感激
  • 这个问题已经被问了一周了..仍然没有答案???这个网站是干什么用的?只是为了发布代码?或尝试解决问题...

标签: ios


【解决方案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
    }
}

【讨论】:

  • 嗨,谢谢您的回答,但它不起作用...它不保存到照片库...不知道为什么???
  • 如果您在设备上进行测试,请确保您的应用有权访问照片。另外,有错误吗?使用我的代码,在 // 错误保存部分,添加一个 NSLog 或一个断点,看看它是否停在那里。
猜你喜欢
  • 2015-01-06
  • 2014-02-02
  • 1970-01-01
  • 2013-07-22
  • 2016-05-01
  • 1970-01-01
  • 2015-05-12
  • 2015-09-25
  • 2015-06-11
相关资源
最近更新 更多