ipad - AVURLAsset 拒绝加载视频

标签 ipad video ios avfoundation ios4

我正在尝试将视频文件作为 AVURLAsset 加载到我的 iPad 应用程序中,使用异步加载来等待它准备就绪。问题是,当我运行它时,我收到一条完全通用的“失败”错误消息,我不知道该怎么做。如果我将视频交给 MPMoviePlayerController,视频就可以正常工作,但 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,顺便说一句,是“未知错误”的错误代码。有点死胡同。有任何想法吗?在尝试加载 Assets 之前,我应该设置什么吗?

最佳答案

已解决。技巧:使用 fileURLWithPath:,而不是 URLWithString:。显然,差异确实非常显着。

关于ipad - AVURLAsset 拒绝加载视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4101380/

相关文章:

ios - [iOS]AVPlayerItemVideoOutput.hasNewPixelBufferForItemTime 无法正常工作

ios - 有没有更好的方法来展平 NSDictionaries 的 NSArray?

iphone - 无法使用 UIScrollView 和 pagingEnabled=YES 禁用弹跳

javascript - 使用 Javascript 在 iPad 上处理待机

iphone - 在Objective-C中,与类方法相比,拥有单例有什么优势?

ios - 不可能更改 UIBarButtonItem 标题?

ios - uiview autosizing displayed with 20 px shift 主要是在播放电影后

html - 使用 HTML5 CSS3 强制 iframe YouTube 视频居中并在后台完全覆盖屏幕

video - 除了渲染帧之外,还有什么方法可以计算 ffmpeg 输出尺寸?

ios - 将 token 发送到后端 strip objective-c