代码之家  ›  专栏  ›  技术社区  ›  Noah Witherspoon

AVURLAsset拒绝加载视频

  •  40
  • Noah Witherspoon  · 技术社区  · 14 年前

    我正在尝试将视频文件作为 AVURLAsset 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是“未知错误”的错误代码。有点死胡同。有什么想法吗?在我尝试加载资产之前,是否应该设置一些内容?

    3 回复  |  直到 13 年前
        1
  •  116
  •   Noah Witherspoon    14 年前

    解决了的。诀窍:使用 fileURLWithPath: ,不是 URLWithString: . 显然,这一差别真的非常显著。

        2
  •  6
  •   Edwin Iskandar    11 年前

    如果任何人在使用fileURLWithPath之后仍然对此有问题,请尝试在使用int时请求时间数组中的nstimeInterval。

        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
  •  6
  •   naituw    10 年前

    -[NSURL fileURLWithPath:] 以创建URL并仍然得到相同的错误。

    AVURLAssetReferenceRestrictionsKey ,

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