iPhone SDK: Stopping a Video
How can I stop a video once I navigate away from a view and make the video play again when I get back to the original view again?
Here is the c开发者_C百科ode to play the video in the original view:
- (void)viewDidLoad {
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Video" ofType:@"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.view.frame = CGRectMake(104.0, 134.0, 200.0, 250.0);
[self.view addSubview:theMovie.view];
[theMovie play];
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}
- Make
theMovie
instance var - Stop playing in the
-(void) viewWillDisappear:(BOOL)animated
And it should start playing when you navigate back to this view. Or move this code to -(void) viewDidAppear:(BOOL)animated
精彩评论