0

I would like to know how to play a video while my app is loading, then navigate to next page in an ios app, using a MPMoviePlayerController. I am loading the video in the viewDidLoad. How can I to move to the next page after the video has finished?

Sample Code Here:

  - (void)viewDidLoad
  {
      NSLog(@"Welcome to Home Page");
      [super viewDidLoad];
      self.parentViewController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg-image-new.png"]];

      NSBundle * bundle =[NSBundle mainBundle];
      NSString * moviepath = [bundle pathForResource:@"opening_ani" ofType:@"mp4"];
      NSURL * movieurl = [[NSURL fileURLWithPath:moviepath]retain];
      MPMoviePlayerController * themovie = [[MPMoviePlayerController alloc]initWithContentURL:movieurl];
      themovie.view.frame=CGRectMake(0, 0, 1024, 768);
      [self.view addSubview:themovie.view];
      [themovie play];
      [themovie setShouldAutoplay:NO];
 }
Mike D
  • 4,938
  • 6
  • 43
  • 99
user1567555
  • 21
  • 1
  • 7

1 Answers1

0

UPDATE:

I am not 100% certain you can play video while the application loading. There is a great explanation here.


In your view controller above, before calling [themovie play], you can register for a notification that playback finished:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleNotification:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

In you view controller, you will have to define a method handleNotification::

    -(void)handleNotification:(NSNotification*)notification {
        if ( [notification.name isEqual:MPMoviePlayerPlaybackDidFinishNotification] ) {
            [[NSNotificationCenter defaultCenter] removeObserver:self
                                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                                          object:nil];
            // move on to your next view here
        }
    }

More about notifications in iOS, it is very useful in general. Also, here are all the details about MPMoviePlayer, there is a section listing all the possible notifications and their details.

Community
  • 1
  • 1
Mike D
  • 4,938
  • 6
  • 43
  • 99