1. To use mpmovieplayerviewcontroller, you must first add mediaplayer. framework.
2. Add the following code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad { [super viewDidLoad]; NSString *url = [[NSBundle mainBundle] pathForResource:@"TaylorSwift-LoveStory" ofType:@"mp4"]; MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]]; //-- add to view--- [self.view addSubview:playerViewController.view]; //---play movie--- MPMoviePlayerController *player = [playerViewController moviePlayer]; [player play]; }- (void) movieFinishedCallback:(NSNotification*) aNotification { MPMoviePlayerController *player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player stop]; [self.view removeFromSuperView]; [player autorelease];}
3. The shouldautorotatetointerfaceorientation: interfaceorientation method can be modified on a horizontal screen to return YES.
Note: The above method can be used to directly play the locally m3u8 format or online video.
Nsurl can be directly initialized:
Nsurl * videopathurl = [nsurl urlwithstring: urlstr]; // urlstr is the video playback address.
For playing a local video. Initialize as follows:
Nsurl * videopathurl = [[nsurl alloc] initfileurlwithpath: urlstr];
Turn: http://re-reference.iteye.com/blog/1106324
Mpmovieplayerviewcontroller for simple MP4 playback