2

我以全屏模式启动 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];
}
4

3 回答 3

4

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

  • 到目前为止,这是我想出的:

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

是不是用视频播放器全屏后主视图没有开始重绘?(在全屏下暂停重绘视图应该可以提高视频播放的性能。据我所知,应该是这种情况。)

  • 这是一个解决方案: (tkx go to my university who had the original problem)

不要进入全屏模式,只需将 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
  • 旋转问题的解决方法:

编写旋转代码:)

于 2011-10-18T13:56:48.117 回答
4

改变

player.controlStyle = MPMovieControlStyleFullscreen; 

player.controlStyle = MPMovieControlStyleDefault; 

并在 MPMoviePlayerDidExitFullscreenNotification

 [player setControlStyle:MPMovieControlStyleNone];
于 2011-12-26T04:44:21.830 回答
-2
[moviePlayer stop];
[moviePlayer release];
[moviePlayer.view removeFromSuperview]; 
于 2011-10-17T14:31:36.240 回答