0

I have an application with a TabBarController containig two TabBars with a NavigationController.

In the first tabbar, I have a ViewController containing some buttons. One of these buttons enable the user to play video. And all run fine for the moment.

My problem is that when the video is being played and I move to the second TabBar, the video continue playing (I hear the sound), then if I come back to the first TabBar (where there is my buttons) the application crashes without any notification.

I don't understand if it's a memory problem or something else.

Any suggestions?

Here is the function used :

-(IBAction)playMovie:(id)sender  
{  
    videoView = [[UIViewController alloc]initWithNibName:@"video" bundle:nil];
    videoView.title = @"title";
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video.mp4" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];

    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(moviePlaybackComplete:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayerController];

    testbtnAppDelegate *appDelegate = (testbtnAppDelegate *)[[UIApplication sharedApplication] delegate];

    videoView.view=moviePlayerController.view;

    [moviePlayerController play];

    [appDelegate.navController  pushViewController:videoView animated:YES];

    }


- (void)moviePlaybackComplete:(NSNotification *)notification  
{  
    moviePlayerController = [notification object];  
    [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                    name:MPMoviePlayerPlaybackDidFinishNotification  
                                                  object:moviePlayerController];  

    [moviePlayerController.view removeFromSuperview];  
    [moviePlayerController release];  
} 
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
hafedh
  • 539
  • 1
  • 9
  • 26
  • Any idea ? I meen how to deal with the video when I move to another view. How can I stop it or let it playing. – hafedh Mar 11 '11 at 19:59

1 Answers1

0

[moviePlayerController pause];

before u go to secondtab pause.