iphone – 进入后台时MPMoviePlayerViewController变黑
发布时间:2020-12-14 19:22:04 所属栏目:百科 来源:网络整理
导读:我有MPMoviePlayerViewController的问题,当应用程序进入后台然后我再次启动它或去另一个viewControllers电影变黑!我的电影在我的菜单背景中播放,这是我的代码: EIDTED代码: -(void)viewDidLoad { [self moviePlayer2]; } - (void) moviePlayer2 { NSStrin
我有MPMoviePlayerViewController的问题,当应用程序进入后台然后我再次启动它或去另一个viewControllers电影变黑!我的电影在我的菜单背景中播放,这是我的代码:
EIDTED代码: -(void)viewDidLoad { [self moviePlayer2]; } - (void) moviePlayer2 { NSString *path = [[NSBundle mainBundle] pathForResource:@"cloud" ofType:@"mp4"]; player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; player.view.userInteractionEnabled = YES; player.moviePlayer.repeatMode = YES; player.moviePlayer.scalingMode = MPMovieScalingModeFill; player.moviePlayer.controlStyle = MPMovieControlStyleNone; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:[player moviePlayer]]; [[player moviePlayer] play]; [self.view addSubview:player.view]; } -(void) moviePlayBackStateChange: (NSNotification *) note { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:[player moviePlayer]]; [[player moviePlayer] play]; //[player release]; NSLog(@"FINISHED"); } 谢谢 . 解决方法
我想你可能需要在下面添加代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:[player moviePlayer]]; 并在moviePlayBackStateChange方法中处理电影状态. [[player moviePlayer] play]; 然后电影将继续播放. -(void) pauseMovieInBackGround { [player moviePlayer] pause]; [player.view removeFromSuperview]; } -(void) resumeMovieInFrontGround { [self.view addSubview:player.view]; [[player moviePlayer] play]; } 希望这可以帮助你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |