Movie playback stops in the middle
<p>I have view with three buttons.First button click takes to another view Controller that simply displays image.
Second Button click takes to another view controller that plays a a movie.
Third button takes to another view controller that has a webview that loads a html page.
If I press my First button , later on press second button, my movie plays perfectly.
If I press third button &amp; then press second button, my movie file hungs up, it doesnt play</p>

<p>For the third button the code I am using is</p>

<pre><code>     - (void)viewDidLoad {
        [super viewDidLoad];

         //allowsInlineMediaPlayback determines whether HTML5 videos play inline or use the native full-screen controller
         self.webView.allowsInlineMediaPlayback = YES;

         //mediaPlaybackRequiresUserAction allows the javascript to trigger Mediaplayback without user interaction
         self.webView.mediaPlaybackRequiresUserAction = NO;

         self.playerPath = [[BundleUtils bundleDirectoryFor:nil] stringByAppendingPathComponent:@"HTMLplayer"];
         NSString* indexFilePath = [self.playerPath stringByAppendingPathComponent:@"index.html"];
         NSURL* indexUrl = [NSURL fileURLWithPath:indexFilePath];
         [self.webView loadRequest:[NSURLRequest requestWithURL:indexUrl]];

    }


    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        for (id v in self.browserView.subviews)
            if ([[v class] isSubclassOfClass: [UIScrollView class]])
                ((UIScrollView *)v).bounces = NO;
    }

    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Load Error", @"") 
                                                        message:[error localizedDescription]
                                                       delegate:nil 
                                              cancelButtonTitle:NSLocalizedString(@"OK", @"")
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];    
    }


    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Overriden to allow any orientation.
        return YES;
    }


    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc. that aren't in use.
    }


    - (void)viewDidUnload {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }


    - (void)dealloc {

        [webView stopLoading];
        [webView release];
    self.webView = nil;
        [super dealloc];
    }


    @end


The code used for movie playback

-(void)viewWillDisappear:(BOOL) animated
{  

    if(mp) {
        [mp stop];
    }


}



- (id)initWithPath:(NSString *)moviePath
{ 
    mp.controlStyle =  MPMovieControlStyleNone;
    // Initialize and create movie URL
    if (self == [super init])
    {
        movieURL = [NSURL fileURLWithPath:moviePath];    
        [movieURL retain];

    }
    return self;
}


- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{   
    if(test == YES ){
        [mp setControlStyle:MPMovieControlStyleNone];
    }
    else
        [mp setControlStyle:MPMovieControlStyleFullscreen];

#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200
    NSString *deviceModel = [NSString stringWithFormat: @"Device Type: %@\n", [[UIDevice currentDevice] model]];    
    NSRange range = [deviceModel rangeOfString:@"iPad"];


    if(range.location != NSNotFound){
        if ([mp loadState] != MPMovieLoadStateUnknown)
        {
            [[NSNotificationCenter  defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200

            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            {
                // load the content controller object for Pad-based devices
                [[self view] setBounds:CGRectMake(0, 0, 1024, 768)];

            }

            else
#endif
            { 
            [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
            }
            //[mp view].clipsToBounds = YES;

            UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
            if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ){
#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200

                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                {
                    // load the content controller object for Pad-based devices
                    [[mp view] setFrame:CGRectMake(0, 0, 1024, 768)];

                }

                else
#endif
                { 
                    [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];
                }
                //[[mp view] setFrame:CGRectMake(0, 0, 1024, 748)];
                            }
            else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight ){

#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200

                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                {
                    // load the content controller object for Pad-based devices
                    [[mp view] setFrame:CGRectMake(0, 0, 1024, 768)];

                }

                else
#endif
                { 
                    [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];
                }
                //[[mp view] setFrame:CGRectMake(0, 0, 1024, 748)];

            }

            [[self view] addSubview:[mp view]];   
            [mp play];

        }
    }
    else

    {  

        if ([mp loadState] != MPMovieLoadStateUnknown)
        {
            [[NSNotificationCenter  defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
            UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
            if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
                [[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:NO];
            }
            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200

            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            {
                // load the content controller object for Pad-based devices
                [[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
                [[self view] setCenter:CGPointMake(160, 240)];
                [[mp view] setFrame:CGRectMake(0, 0, 1024, 748)];

            }

            else
#endif
            { 
                [[self view] setBounds:CGRectMake(0, 0, 480, 330)];
                [[self view] setCenter:CGPointMake(160, 240)];
                [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];
            }
//          [[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
//          [[self view] setCenter:CGPointMake(160, 240)];
//          [[mp view] setFrame:CGRectMake(0, 0, 1024, 748)];
            [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
            [[self view] addSubview:[mp view]];   
            [mp play];

        }
    }
#endif

}


/*---------------------------------------------------------------------------
 * For 3.1.x devices
 * For 3.2 and 4.x see moviePlayerLoadStateChanged: 
 *--------------------------------------------------------------------------*/

- (void) moviePreloadDidFinish:(NSNotification*)notification 
{   
    //NSLog(@"moviePreloadDidFinish");
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
    [mp play];

}

/*---------------------------------------------------------------------------
 * 
 *--------------------------------------------------------------------------*/
- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self dismissModalViewControllerAnimated:NO];   

}

/*---------------------------------------------------------------------------
 *
 *--------------------------------------------------------------------------*/
- (void) readyPlayer
{   
    //NSLog (@"readyPlayer");
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    mp.scalingMode= MPMovieScalingModeAspectFit;




    if ([mp respondsToSelector:@selector(loadState)]) 
    {
        // Set movie player layout
#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200 

        //[mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setControlStyle:MPMovieControlStyleNone];
        [mp setFullscreen:YES];
#endif

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
#if __IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200 

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
#endif
    }  
    else
    {
        // Register to receive a notification when the movie is in memory and ready to play.
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
        //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

    }

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}

/*---------------------------------------------------------------------------
 * 
 *--------------------------------------------------------------------------*/

- (void) loadView
{ 
    isFirstLoad = YES;
    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
    [[self view] setBackgroundColor:[UIColor blackColor]];
    self.view.clipsToBounds = YES;
    self.view.autoresizesSubviews = YES;

    if(mp) {
        [mp stop];
    }

    UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        [[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:NO];
    }       
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)dealloc 
{
    [mp release];
    [movieURL release];
    [super dealloc];
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

#pragma mark -
#pragma mark InterfaceOrientationMethods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft|| toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
        //[self changeTheViewToPortrait:NO andDuration:duration];
    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

    if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
        [self changeTheViewToPortrait:NO andDuration:0.0];
    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){

    }
    else if (isFirstLoad){

        isFirstLoad = FALSE;
        UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
        if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ){

            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];


            //[[self view] setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
            [[self view] setBounds:CGRectMake(0, 0, 1024, 748)];
            //[[self view] setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
        }
        else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight ){
            NSLog(@"UIInterfaceOrientationLandscapeRight");

            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];


            [[self view] setBounds:CGRectMake(0, 0, 1024, 748)];

        }


    }

    [UIView commitAnimations];

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------


@end
</code></pre>
