- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- ‘’‘’‘’
- NSString *filepath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
- NSURL *fileURL = [NSURL fileURLWithPath:filepath];
- MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
- [self.viewController.view addSubview:theMovie.view];
- theMovie.fullscreen = YES;
- theMovie.controlStyle = MPMovieControlStyleNone;
- if ([theMovie respondsToSelector:@selector(prepareToPlay)]) {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(stopPlayerCallback:)
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:theMovie];
- [theMovie prepareToPlay];
- }
- return YES;
- }
播放完视频后,
- -(void)stopPlayerCallback:(NSNotification*)aNotification
- {
- MPMoviePlayerController* theMovie = [aNotification object];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
- object:theMovie];
- [theMovie.view removeFromSuperview];
- }