我想全屏查看MPMoviePlayerController。它可以是水平视图。 MPMoviePlayerController只能在纵向视图中使用。这是我的代码尝试:
创建MPMoviePlayerController:
NSURL *movieURL = [NSURL URLWithString:previewString];
movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
movieController.view.backgroundColor = [UIColor grayColor];
[detailview addSubview:movieController.view];
[movieController prepareToPlay];
movieController.shouldAutoplay = NO;
[detailview addSubview:movieController.view];
我尝试了上面的代码但是当moviecontroller是全屏时,它只能以纵向模式查看。它无法在横向模式下查看。我只希望在全屏模式下的电影控制器可以在横向模式下查看而没有另一个视图仍然在纵向模式下查看。我该怎么办?
答案 0 :(得分:4)
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
并在.m文件中合成该属性
@synthesize moviePlayer = _moviePlayer;
我的资源文件夹中有电影文件,请相应更改名称:
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video001" ofType:@"MOV"]]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[_moviePlayer prepareToPlay];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
[_moviePlayer stop];
[_moviePlayer play];
并关闭fullScreen我有这样的方法:
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
希望它适合你。
答案 1 :(得分:4)
是的,您可以使用两个通知观察者来更改完整方向。
首先,在 AppDelegate didFinishLaunchingWithOptions
方法中添加两个通知观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
其次,添加方法和属性
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.allowRotation = NO;
}
第三,覆盖supportedInterfaceOrientationsForWindow
方法,您可以返回任何您想要的方向
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}
答案 2 :(得分:1)
我在横向模式下的某个应用中使用了以下代码。
[moviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.repeatMode = MPMovieRepeatModeOne;
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[moviePlayerController play];
答案 3 :(得分:1)
您的方法的挑战在于,只需在视图中添加子视图,处理轮换事件就是您的责任。
听起来你应该使用MPMoviePlayerViewController
代替:
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer play];
如果您在应用中正确设置了方向选项,则旋转将由播放器控制器处理,并将播放纵向和横向内容。如果您的应用目前不支持横向,则电影播放器控制器也不会。