【问题标题】:How to save video to custom album?如何将视频保存到自定义相册?
【发布时间】:2013-12-10 10:44:59
【问题描述】:

我正在尝试将在应用中制作的视频保存到自定义相册。 我已经尝试过Saving Video in an Album Created 提出的解决方案,但是,这些块是异步执行的,导致结果块中的资产为零。

我已成功创建相册,向其写入视频似乎不适用于上述方法。我不知道发生了什么事。有人可以给我提个醒吗?

【问题讨论】:

  • 你试过- (void)assetForURL:(NSURL *)assetURL resultBlock:(ALAssetsLibraryAssetForURLResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock方法了吗?在 resultBlock 你应该有一个非零资产对象
  • 是的,我确实这样做了,资产一直返回为零。 [library assetForURL:assetURL resultBlock:^(ALAsset *asset) { //Add video to group [targetGroup addAsset:asset]; } failureBlock:^(NSError* error) { //Error }];
  • 那么assetURL是从哪里来的呢?
  • 它由AVCaptureFileOutputRecordingDelegate方法提供captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error看起来像这样:NSURL * @"file:///private/var/mobile/Applications/1BB71D35-A37E-4FE3-8D8D-F00DFA925086/tmp/output.mov"

标签: ios ios7 alassetslibrary


【解决方案1】:

你得到的 url 是文件 url,而不是 ALAsset url。

您需要先将该 mov 保存到相机胶卷,然后将其资产引用添加到自定义相册。

查看本教程中的示例代码。

http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/

【讨论】:

  • ALAsset url 成功了 :) 谢谢!我已将解决方案放在 GitHub: VideoAlbumManager 上的单独类中
  • 很高兴听到这个消息并感谢您的工作!短期内对我有用。 :D
【解决方案2】:

对于视频保存支持,只需将以下功能添加到此处提供的类别中: http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/

 -(void)saveVideoLocalUrl:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
 {
    //add the asset to the custom photo album
    [self writeVideoAtPathToSavedPhotosAlbum:assetURL completionBlock:^(NSURL *assetURL, NSError *error)    {
       NSLog(@"error: %@", [error description]);

       [self addAssetURL: assetURL
              toAlbum:albumName
       withCompletionBlock:completionBlock];
    }];
 }

【讨论】:

    猜你喜欢
    • 2012-07-05
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    相关资源
    最近更新 更多