我试图加载视频文件到我的iPad应用作为AVURLAsset
,使用异步加载的东西来等待它准备就绪。问题是,当我运行它时,我得到一个完全通用的“失败”错误消息,我不知道该如何处理。该视频的作品如果我把它交给MPMoviePlayerController
,但AVURLAsset
似乎拒绝与它有任何关系。AVURLAsset拒绝加载视频
代码:
asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:[docPath stringByAppendingPathComponent:@"video.mov"]] options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self composeIfReady];
});
}];
...
- (void)composeIfReady
{
NSError *error = nil;
if([asset statusOfValueForKey:@"tracks" error:&error] == AVKeyValueStatusFailed)
NSLog(@"error loading: %@", [error description]);
if(error == nil)
NSLog(@"okay awesome");
}
输出:
error loading: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)" UserInfo=0x1696f0 {NSUnderlyingError=0x169a40 "The operation couldn’t be completed. (OSStatus error -12936.)"}
-11800,顺便说一句,是 “未知错误” 的错误代码。一种死胡同。有任何想法吗?在我尝试加载资产之前是否应该设置一些内容?
我正在使用fileURLWithPath,仍然得到相同的错误。 – gngrwzrd 2012-01-18 17:59:19
+1 This work for me..Thanks much .. – 2012-05-04 06:14:29
谢谢你verryy多!!!我现在意识到差异很重要,因为它需要一个绝对的URL到URL,所以URLWithString给出的相对URL(/ var/mobile/...)不起作用。 – 2012-05-22 10:08:59