使用MPMoviePlayerController播放视频的总结

-(void)openMovie:(id)sender
{
	NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
	MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; //设置要播放的视频的位置
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:movieController]; //设置视频播放结束后的回调处理
	
	[movieController play]; //播放视频
}

-(void)movieFinish:(NSNotification*)notification
{
	MPMoviePlayerController *movieController = [notification object];
	[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movieController];
	[movieController release]; //释放资源
	movieController = nil;
	
	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}

你可能感兴趣的:(controller)