Calling Function When Video is Done Playback

Discussion in 'iOS Programming' started by paulmatos, Mar 3, 2011.

  1. paulmatos macrumors newbie

    Mar 3, 2011
    Hi all,

    I am trying creating an app that involves transitioning from a playing video to a web screen and was hoping to get some help on an issue I am having. As the title suggests I am trying to call a function that will load up a website once playback of a video is complete.

    The app works like this, user loads app and then clicks on a button to begin the video playback. Here is the code for that:

    		NSBundle *bundle = [NSBundle mainBundle];
    		NSString *moviePath = [bundle pathForResource:@"AdvofaRealtor-s1-part1" ofType:@"m4v"];
    		NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    		MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    		theMovie.scalingMode = MPMovieScalingModeAspectFit;
    		[theMovie setFullscreen:NO];
    		[theMovie play];
    		MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    		[self presentMoviePlayerViewControllerAnimated:moviePlayer];
    		 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(theMoviePlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];

    In the last line there I use MPMoviePlayerPlaybackDidFinishNotification to call the following function:

    - (void) theMoviePlaybackDidFinish:(NSNotification*)notification
    		UIWebView *myWebView;
    		myWebView = [[UIWebView alloc] initWithFrame:(CGRectMake(0,0,768,1010))];
    		[self.view addSubview:myWebView];
    		[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@""]]];
    		[myWebView setScalesPageToFit:YES];

    This code seems to work fine in the simulator but when I view it on the actual iPad it functions differently. In the simulator when the video reaches the end of the playback it will load the webview, but on the iPad when the video finishes playing it simply returns to the default view.

    Am I missing something, sorry if this is a noob answer, I really just started coding for the iphone/ipad.

    Any help would be greatly appreciated. Thank you.
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Hmm not seeing a mistake atm.
    What u could try to do, is
    [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@""]]];
    		[myWebView setScalesPageToFit:YES];
    before the addSubview.

Share This Page