如何使用MPMoviePlayerViewController在本地播放电影?

时间:2010-11-02 11:18:03

标签: iphone objective-c cocoa-touch video mpmovieplayercontroller

我的Resources文件夹中有一个名为lebron.mp4的mp4文件:

-(IBAction)videoButtonClicked:(id)sender{
    NSString *url = [[NSBundle mainBundle] 
                     pathForResource:@"lebron" 
                     ofType:@"mp4"];

    MPMoviePlayerViewController* moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];

    moviePlayerViewController.view.backgroundColor = [UIColor blackColor];
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

    [moviePlayerViewController release];    
}

显示电影播放器​​,但电影无法播放。为什么呢?

1 个答案:

答案 0 :(得分:0)

你试图像这样显示它:

[moviePlayerViewController play];
[window addSubview: MPMoviePlayerViewController.view];