我正在尝试将一个视频文件作为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,顺便说一下,是“未知错误”的错误码。这是个死胡同。有什么想法吗?在尝试加载资产之前,是否应该设置一些内容?
发布于 2010-11-17 12:12:48
解决了。诀窍:使用fileURLWithPath:,而不是URLWithString:。显然,差异真的非常非常显著。
发布于 2013-10-15 23:42:12
如果任何人在使用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];发布于 2014-05-17 23:32:02
如果您正在使用-[NSURL fileURLWithPath:]创建URL,但仍然收到相同的错误。
请检查AVURLAssetReferenceRestrictionsKey,如果您的本地m3u8包含远程资源,可能无法播放。
将该值设置为@(AVAssetReferenceRestrictionForbidNone)应该可以解决问题。
https://stackoverflow.com/questions/4101380
复制相似问题