objective-c - 从 ALAsset URL 创建时,AVAsset 没有轨道或持续时间

标签 objective-c ios4 nsurl alasset alassetslibrary

我正在从 ALAssetsLibrary 中提取所有视频 Assets (基本上是从 native 相机应用程序中录制的所有内容)。然后我对每个视频 Assets 运行一个枚举,对每个视频执行此操作:

 // The end of the enumeration is signaled by asset == nil.
           if (alAsset) {

                 //Get the URL location of the video
               ALAssetRepresentation *representation = [alAsset defaultRepresentation];
               NSURL *url = [representation url];

                 //Create an AVAsset from the given URL
               NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
               AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options];//[AVURLAsset URLAssetWithURL:url options:asset_options];

               //Here is the problem
               NSLog([NSString stringWithFormat:@"%i", [avAsset.tracks count]]);
               NSLog([NSString stringWithFormat:@"%f", CMTimeGetSeconds(avAsset.duration)]);
           }

NSLog 报告我从我的 ALAsset 获得的 AVAsset 有 0 个轨道,并且持续时间为 0.0 秒。我检查了 url,它是“assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV”,这似乎是正确的。我知道 alAsset 实际上是一个视频,而且是正确的视频,因为我已经显示了 alAsset.thumbnail,它显示了视频的正确缩略图。

所有这一切让我相信 avAsset 的初始化出现了问题,但就我的生活而言,我无法弄清楚出了什么问题。谁能帮帮我?

更新:

我想我已经确认 ALAssetRepresentation 给我的 url 是错误的,这很奇怪,因为它给了我正确的缩略图。我在以下位置添加了这段代码:

NSLog([NSString stringWithFormat:@"%i", [url checkResourceIsReachableAndReturnError:&error]]);
NSLog([NSString stringWithFormat:@"%@", error]);

它给了我这个:

0
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x19df60 {}

我仍然不确定是什么原因造成的。我唯一注意到的是 url,即“assets-library://asset/asset.MOV?id=9F482CF8-B4F6-40C2-A687-0D05F5F25529&ext=MOV”与我看到的不同一直在寻找这个。我在别处看到的那个看起来更像“assets-library://asset/asset.MOV?id=1000000394&ext=MOV”,用数字代替字母数字,破折号分隔的名称。

如果有帮助,我正在使用 XCode 4.2 Beta 和 iOS5。如果您能想到什么,请告诉我。谢谢。

最佳答案

好吧,看起来这是 iOS5 beta v1 中的一个错误。我升级到最新的并且它有效。感谢那些看过我的问题的人。

关于objective-c - 从 ALAsset URL 创建时,AVAsset 没有轨道或持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6884966/

相关文章:

ios4 - 尝试构建 ABBYY Mobile OCR SDK 示例代码时出现构建错误

iphone - 将 NSURL 与在其获取请求中使用方括号的 PHP Web 服务一起使用

ios - 将下载的图像从 url 设置为 Imageview - IoS

ios - 从 Storyboard实例化的 UIViewController 扩展

iphone - No type or storage class may be specified here before 'interface'/'interface' iOS 错误(损坏的 Xcode?)

iOS 4 : Is it possible to show Local Notifications during a Telephony Call?

ios - 获取文档目录收件箱文件并移动

objective-c - 已删除 NSManagedObject 从 TableView 中正确删除,然后在保存时重新出现

objective-c - 使用 FBDialog 上传 UIImage

iphone - 从 RSS 数据中的链接获取完整详细信息