How can I play a movie locally with the MPMoviePlayerViewController?

百般思念 提交于 2020-01-07 04:45:06

问题


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

?



来源:https://stackoverflow.com/questions/4077096/how-can-i-play-a-movie-locally-with-the-mpmovieplayerviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!