我正在尝试使用 iOS 4.1 播放 iPhone 上资源文件夹中的视频文件。MPMoviePlayerViewController 显示视图,但它只显示“正在加载电影...”,并且活动指示器旋转。有谁知道这是什么原因?我尝试过各种应该在 iPhone 上运行的视频格式,每次都得到相同的结果。
电影播放器响应显示和隐藏控件等操作。
我的代码:
-(void) playVideoNamed:(NSString *)videoName
{
// I get the path like this so the user can enter extension in the filename
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath], videoName];
NSLog(@"Path of video file: %@", path);
RootViewController *rootController = [(DerpAppDelegate *)[[UIApplication sharedApplication] delegate] viewController];
NSURL *url = [NSURL URLWithString:path];
MPMoviePlayerViewController *vc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
vc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[rootController presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer prepareToPlay]; // Not sure about this... I've copied this code from various others that claims this works
[vc.moviePlayer play];
}