- (IBAction) openFourthInfo:(id)sender{
NSURL *url = [NSURL URLWithString:@"http://my-video.mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userPressedDone:)
name:MPMoviePlayerWillExitFullscreenNotification
object:player];
[self.view addSubview:player.view];
[mainView setHidden:YES]; //Need to hide another subview here
player.fullscreen = YES;
[player play];
}
这就是我给玩家打电话的方式。在userPressedDone:
和moviePlaybackComplete:
我基本上只设置mainView.setHidden = YES;
,删除观察者,删除并释放播放器。
没什么特别的。知道为什么玩家会留在肖像中吗? 我试过了
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
它为更改状态栏设置了动画,但视图保持不变。添加
[[player view] setBounds:CGRectMake(20, 0, 480, 320)];
[[player view] setCenter:CGPointMake(160, 240)];
[[player view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
没有任何反应。用player view
替换self view
,我只是让父视图旋转,而不是播放器视图。
问题在哪里,我该如何解决?我正在尝试5个小时左右-.-
谢谢!
答案 0 :(得分:5)
默认情况下,MPMoviePlayerController不再在横向上工作,因此要使其在横向中工作,您需要将变换应用于视图。
UIView * playerView = [moviePlayerController view];
[playerView setFrame: CGRectMake(0, 0, 480, 320)];
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[playerView setTransform: landscapeTransform];
此外,如果您需要常规全屏控制,请使用以下示例。
moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;