AVURLAsset 拒绝加载视频 [英] AVURLAsset refuses to load video
问题描述
我正在尝试将视频文件作为 AVURLAsset
加载到我的 iPad 应用程序中,使用异步加载的东西来等待它准备就绪.问题是,当我运行它时,我收到一条完全通用的失败"错误消息,我不知道该怎么办.如果我将它交给 MPMoviePlayerController
,视频就可以工作,但是 AVURLAsset
似乎拒绝与它有任何关系.
I'm trying to load a video file into my iPad app as an AVURLAsset
, using the asynchronous-loading stuff to wait for it to be ready. Problem is, when I run it, I get a completely generic "failure" error message that I have no idea what to do with. The video works if I hand it to an MPMoviePlayerController
, but AVURLAsset
seems to refuse to have anything to do with it.
代码:
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 顺便说一下,是未知错误"的错误代码.有点死胡同.有任何想法吗?在我尝试加载资产之前,我应该设置什么吗?
-11800, by the way, is the error code for "unknown error". Kind of a dead end. Any ideas? Is there something I should be setting up before I try to load the asset?
推荐答案
已解决.诀窍:使用 fileURLWithPath:
,而不是 URLWithString:
.显然,差异非常非常显着.
Solved. The trick: use fileURLWithPath:
, not URLWithString:
. Apparently the difference is really, really significant.
这篇关于AVURLAsset 拒绝加载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!