MPMoviePlayerController未在iOS5.0上关闭

时间:2011-10-17 14:24:52

标签: iphone objective-c ios5 mpmovieplayer mpmoviewcontroller

我以全屏模式启动MPMoviePlayerController,然后使用默认按钮关闭它。它就像iOS4.3上的魅力一样,但在iOS5.0上留下了黑屏:(

我做错了吗?这是我的代码:

显示播放器:

- (void)showVideo {

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];  

// Register to receive a notification when the movie has finished playing.  
[[NSNotificationCenter defaultCenter] addObserver:self  
                                         selector:@selector(moviePlayBackDidFinish:)  
                                             name:MPMoviePlayerPlaybackDidFinishNotification  
                                           object:moviePlayer];      



moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = YES;  
moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame];
moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633);    

[self.view addSubview:moviePlayer.view];  

[moviePlayer setFullscreen:YES animated:NO];  
}

关闭播放器:

- (void) moviePlayBackDidFinish : (NSNotification *) notification
{
MPMoviePlayerController *moviePlayer = [notification object];  
[[NSNotificationCenter defaultCenter] removeObserver:self  
                                                name:MPMoviePlayerPlaybackDidFinishNotification  
                                              object:moviePlayer];  

[moviePlayer.view removeFromSuperview];

[moviePlayer stop];
[moviePlayer release];  

//otherwise the status bar hides or changes color from time to time 
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

3 个答案:

答案 0 :(得分:4)

我在更新到iOS5后一直在尝试解决同样的问题。

  • 这是我到目前为止所提出的:
  

进入全屏模式后,这是MPMoviePlayerController中的一个错误。基本上你不能离开全屏模式。但这应该   如果我们只删除MPMoviePlayerController就可以解决。但没有运气   那里...

     

在使用视频播放器进入全屏后,主视图是否无法重新开始重绘? (暂停重绘视图   在de fullscreen下应该提高视频播放的性能。和   据我所知,情况确实如此。)

  • 这是一个解决方案:(tkx去找我原来问题的大学)
  

不要进入全屏模式,只需将MPMoviePlayerController拉伸到父视图边界即可。这里的问题   就是如果我们旋转我们的屏幕自动旋转那个   全屏模式给出的是不会被使用。

//instead of going to fullscreen
//[moviePlayer setFullscreen:YES animated:YES];    
[moviePlayer.view setFrame:self.view.bounds];

//when the movie has finished playing release it
  • 解决轮换问题:
  

写轮换代码:)

答案 1 :(得分:4)

更改

player.controlStyle = MPMovieControlStyleFullscreen; 

player.controlStyle = MPMovieControlStyleDefault; 

并在MPMoviePlayer中执行了ExitFullscreen Notification

 [player setControlStyle:MPMovieControlStyleNone];

答案 2 :(得分:-2)

[moviePlayer stop];
[moviePlayer release];
[moviePlayer.view removeFromSuperview];