Switching view controllers at the end of a movie's playback?
In my app, there's a UIButton that the end user can push, which pushes a view controller that plays a video in a frame using MPMoviePlayerController.
I'd like to be able to detect w开发者_运维知识库hen the video reaches it's end, and when that happens, push a new view controller. Though I can't seem to find the code that can do this.
Does anyone know how to do this?
The video playback code just looks like this:
//video stuff
CGRect myVideoRect = CGRectMake(0.0f, 145.0f, 320.0f, 160.0f);
movieUrl = [[NSBundle mainBundle] URLForResource:@"myMovie" withExtension:@"m4v"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
[[moviePlayerController view] setFrame:myVideoRect];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
Thanks!
Register your view controller to listen to playbackdidfinish notification for the player:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
Then implement a playbackFinished method where you can push a new view controller or perform any other action.
精彩评论