【发布时间】:2014-05-12 00:18:23
【问题描述】:
我从我的 iPhone 照片库中检索了电影文件,并将它们保存到我的应用程序的 Documents 目录中。当我单击一个电影文件时,我想使用 MPMoviePlayerController 来播放它。不幸的是,它无法播放电影文件并出现这样的错误:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
我找了很久才解决这个问题。有人说格式可能不支持。电影文件是从照片库中检索的,所以格式应该没问题。另外,我将文件复制到 NSBundle 并且 MPMoviePlayerController 可以播放它。所以文件没问题。以下是我的代码:
NSString *newstr = [mFilePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
DLog(@"the raw is %@ the newstr is %@", mFilePath, newstr);
NSURL *url = [NSURL URLWithString:newstr];
DLog(@"the url is %@", url);
#if 0
NSBundle *bundle = [NSBundle mainBundle];
if (bundle) {
NSString *path = [bundle pathForResource:@"test" ofType:@"MOV"];
if (path) {
url = [NSURL fileURLWithPath:path];
DLog(@"the new url is %@", url);
}
}
#endif
mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[mPlayer setMovieSourceType:MPMovieSourceTypeFile];
[mPlayer prepareToPlay];
[mPlayer.view setFrame:self.view.bounds];
[mPlayer play];
[self.view addSubview:mPlayer.view];
【问题讨论】:
-
得到同样的错误,但当我直接从服务器播放时没有......
标签: mpmovieplayercontroller movie video-player