3

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

 // 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 秒。我检查了网址,它是“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 {}

我仍然不确定是什么原因造成的。我唯一注意到的是网址,即“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。如果你能想到什么,请告诉我。谢谢。

4

1 回答 1

0

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

于 2011-07-31T02:43:41.117 回答