我有一个MPMoviePlayerController
初始化如下:
//Code in my UIViewController
@property (nonatomic, strong) UIView *myVideoView;
@property (nonatomic, strong) MPMoviePlayerController *myVideoPlayer;
- (void) initializeVideoPlayer
{
CGRect frame = CGRectMake(0, 70, self.view.frame.size.width, 200);
self.myVideoView = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:self.myVideoView];
NSURL *videoURL = [NSURL fileURLWithPath:path];
self.myVideoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.myVideoPlayer.controlStyle = MPMovieControlStyleEmbedded;
self.myVideoPlayer.shouldAutoplay = YES;
[self.myVideoPlayer.view setFrame: self.myVideoView.bounds];
[self.myVideoView addSubview: self.myVideoPlayer.view];
//Play video
[self.myVideoPlayer prepareToPlay];
[self.myVideoPlayer play];
}
我的问题是当用户将手机旋转为横向而不是全屏时,如何让视频全屏播放。
我尝试将以下内容添加到我的UIViewController
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
[self.myVideoPlayer setFullscreen:YES animated:YES];
}
else
{
[self.myVideoPlayer setFullscreen:NO animated:YES];
}
}
但是,这样做的问题是,一旦播放器处于全屏状态,就willAnimateRotationToInterfaceOrientation
不会再调用了;因此,即使用户旋转回纵向,视频仍处于全屏状态。