NavigationController 上的视频问题 + TabBar控制器

发布于 2024-10-21 09:59:45 字数 1780 浏览 1 评论 0原文

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

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

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

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

有什么建议吗?

这是使用的函数:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-10-28 09:59:45

[moviePlayerController 暂停];

在你进入第二个选项卡之前暂停。

[moviePlayerController pause];

before u go to secondtab pause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文