Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

ipad - AVURLAsset refuses to load video

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.

Code:

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");
}

The output:

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, 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Solved. The trick: use fileURLWithPath:, not URLWithString:. Apparently the difference is really, really significant.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...