[英]how to dismiss MPMoviePlayer ? properly from one ViewController to another
I am using the Notification Center to receive the MPMoviePlayerPlaybackDidFinishNotification, which works as expected. 我正在使用通知中心来接收MPMoviePlayerPlaybackDidFinishNotification,它可以按预期工作。
NSURL * url = [[NSURL alloc] initWithString:@"http://INFINITECREATIVEUNIVERSE.COM/Media/module_1_Dec/c_January27AffactPerfect.mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(0, 0, 500, 260)];
[self.view addSubview:moviePlayer.view];
//Some addiontal customization
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
moviePlayer.shouldAutoplay = YES;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
//moviePlayer.endPlaybackTime = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playMovieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
The selector does what I would like it to do. 选择器会执行我想要的操作。
-(void)playMovieFinished:(NSNotification*)theNotification
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// Change Segue ID Here
[self performSegueWithIdentifier:@"VC_5" sender:self];
}
My problem occurs when I click next button while the video is still playing. 当我仍在播放视频时,单击下一步按钮会出现我的问题。 When my next ViewController appears there is no video and I can still hear the audio from the previous ViewController.
当我的下一个ViewController出现时,没有视频,我仍然可以听到前一个ViewController的音频。
My question is: How do I properly dismiss the View Controller and the MPMoviePlayer. 我的问题是:如何正确解雇视图控制器和MPMoviePlayer。 I am lost.
我搞不清楚了。 I downloaded the example MoviePlayer project from Apple, but it is now deprecated and it does not work properly.
我从Apple下载了示例MoviePlayer项目,但现在已弃用该项目,并且该项目无法正常工作。 I am lost on how to make this work.
我迷失了如何使这项工作。 I am crossing my fingers that I have asked the question correctly.
我用手指交叉问了正确的问题。 Please have mercy on my novice question.
请怜悯我的新手问题。 Thank you robert
谢谢罗伯特
use this code 使用此代码
-(void)playMovieFinished:(NSNotification*)theNotification
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer stop];
// Change Segue ID Here
[self performSegueWithIdentifier:@"VC_5" sender:self];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.