【发布时间】:2018-01-15 20:12:50
【问题描述】:
我有一个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 就不再被调用;因此,即使用户旋转回纵向,视频仍处于全屏状态。
【问题讨论】:
标签: objective-c ios mpmovieplayercontroller