0

我有一个带有 TabBarController 的应用程序,其中包含两个带有 NavigationController 的 TabBar。

在第一个标签栏中,我有一个包含一些按钮的 ViewController。这些按钮之一使用户能够播放视频。目前一切运行良好。

我的问题是,当视频正在播放并且我移动到第二个 TabBar 时,视频继续播放(我听到声音),然后如果我回到第一个 TabBar(那里有我的按钮)应用程序崩溃而没有任何通知。

不知道是内存问题还是其他问题。

有什么建议么?

这是使用的功能:

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

1 回答 1

0

[moviePlayerController 暂停];

在你去 secondtab 之前暂停。

于 2011-04-06T09:17:41.700 回答