How can I play a movie locally with the MPMoviePla

2019-08-23 11:51发布

问题:

I have an mp4 file called lebron.mp4 in my Resources folder:

-(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];    
}

Displays the movie player, but the movie doesn't play. Why?

回答1:

did you try to display it like this :

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

?