NSString *path = [[NSBundle mainBundle] pathForResource:@"test1" ofType:@"mov"];
if (path) {
NSLog(@"路径正确");
NSURL *movieURL = [[NSURL alloc] initFileURLWithPath:path];
self.moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayer.view setFrame:self.view.bounds];
self.moviePlayer.shouldAutoplay=YES;
[self.moviePlayer setControlStyle:MPMovieControlStyleNone];
[self.moviePlayer setFullscreen:YES];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[self.view addSubview:self.moviePlayer.view];
} else {
NSLog(@"路径错误");
}
NSURL *movieURL = [[NSURL alloc] initFileURLWithPath:path];
NSURL *movieURL = [NSURL fileURLWithPath:path];
PS:播放器的对象必须是self的一个属性 ,否则播放5秒左右就会中断。