开发者

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];      
}


  1. Make theMovie instance var
  2. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜