AVAsset从ALAsset URL创建时没有轨道或持续时间

问题描述:

我从ALAssetsLibrary(基本上是从本机相机应用程序记录的所有内容)提取所有视频资产。我然后在每个视频的资产,这样做是为了每个视频运行枚举:AVAsset从ALAsset URL创建时没有轨道或持续时间

// 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给我是错误的,这是奇怪的,因为它给了我正确的缩略图。我添加了这个代码:

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中的一个错误。我升级到最新,它的工作。感谢那些看过我的问题的人。

+0

在iOS 7中可以吗?我在ios7中遇到了问题。 –