NavigationController 上的视频问题 + TabBar控制器
我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[moviePlayerController 暂停];
在你进入第二个选项卡之前暂停。
[moviePlayerController pause];
before u go to secondtab pause.