我試圖加載視頻文件到我的iPad應用作爲AVURLAsset
,使用異步加載的東西來等待它準備就緒。問題是,當我運行它時,我得到一個完全通用的「失敗」錯誤消息,我不知道該如何處理。該視頻的作品如果我把它交給MPMoviePlayerController
,但AVURLAsset
似乎拒絕與它有任何關係。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,順便說一句,是 「未知錯誤」 的錯誤代碼。一種死衚衕。有任何想法嗎?在我嘗試加載資產之前是否應該設置一些內容?
我正在使用fileURLWithPath,仍然得到相同的錯誤。 – gngrwzrd 2012-01-18 17:59:19
+1 This work for me..Thanks much .. – 2012-05-04 06:14:29
謝謝你verryy多!!!我現在意識到差異很重要,因爲它需要一個絕對的URL到URL,所以URLWithString給出的相對URL(/ var/mobile/...)不起作用。 – 2012-05-22 10:08:59