【问题标题】:AVURLAsset refuses to load videoAVURLAsset 拒绝加载视频
【发布时间】:2011-05-05 07:44:06
【问题描述】:

我正在尝试将视频文件以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,顺便说一下,是“未知错误”的错误代码。有点死胡同。有任何想法吗?在尝试加载资产之前我应该​​设置什么?

【问题讨论】:

    标签: ipad video ios avfoundation ios4


    【解决方案1】:

    解决了。诀窍:使用fileURLWithPath:,而不是URLWithString:。显然差异是非常非常重要的。

    【讨论】:

    • 非常感谢!!!我现在确实意识到差异很大,因为它需要文件的绝对 URL,因此 URLWithString 给出的相对 URL (/var/mobile/...) 不起作用。
    • 对我来说,在使用 URLWithString 时,回调从未被调用过——甚至没有告诉我错误。不过,使用fileURLWithPath 它可以工作。这是严重的缺陷...... -.-
    • fileURLWithPath 用于播放捆绑包中的音频,但我无法播放 url 中的音频。
    • 我也遇到了一个问题,请查看并建议:stackoverflow.com/questions/51239586/…
    【解决方案2】:

    如果有人在使用 fileURLWithPath 后仍然遇到此问题,请尝试在使用 int(s) 时在时间数组中请求 NSTimeIntervals。

    这不起作用:

        NSMutableArray *playbackTimes = [NSMutableArray array];
        for (int i = 0; i <= 10; i ++) {
            [playbackTimes addObject:@(i)];
        }
    
        [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];
    

    这行得通:

        NSMutableArray *playbackTimes = [NSMutableArray array];
        for (int i = 0; i <= 10; i ++) {
             [playbackTimes addObject:@((NSTimeInterval)i)];
         }
    
         [self.videoPlayer requestThumbnailImagesAtTimes:playbackTimes timeOption:MPMovieTimeOptionNearestKeyFrame];
    

    【讨论】:

    • 这是我的问题。谢谢,埃德温。
    • 你能做一个快速的版本吗?请
    【解决方案3】:

    如果您使用 -[NSURL fileURLWithPath:] 创建 URL,但仍然出现相同的错误。

    检查AVURLAssetReferenceRestrictionsKey, 如果本地 m3u8 包含远程资源,它可能无法播放。

    将值设置为@(AVAssetReferenceRestrictionForbidNone) 应该可以解决问题。

    【讨论】:

    • 你在哪里设置的?
    • @CodyMace 这是AVURLAsset的选项键,见-[AVURLAsset URLAssetWithURL:options:]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多