如何在模拟调用的视图上使用MPMoviePlayerViewController全屏播放电影

时间:2012-06-25 15:34:58

标签: objective-c ios5 mpmovieplayercontroller

在视图中,我有这个代码来全屏播放电影:

NSURL *movieURL = [NSURL URLWithString:@"http://stream.qtv.apple.com/events/jan/1201oihbafvpihboijhpihbasdouhbasv/12pibasvpqihbsdfvihbasdv01_iphone_vod_ref.mov"];

self.mpc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
NSLog(@"self mpc: %@", self.mpc);
[[NSNotificationCenter defaultCenter] addObserver:self  
                                         selector:@selector(moviePlayBackDidFinish:)  
                                             name:MPMoviePlayerPlaybackDidFinishNotification  
                                           object:self.mpc ];
self.mpc.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
self.mpc.moviePlayer.shouldAutoplay = YES; 
self.mpc.view.frame = self.view.frame;

[self.view addSubview:self.mpc.view];
self.mpc.moviePlayer.fullscreen = YES;
[self.mpc.moviePlayer play];

使用此代码调用视图本身

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
 bundle: nil];
 TestViewController *controller = [mainStoryboard 
 instantiateViewControllerWithIdentifier: @"testController"];
 [self presentModalViewController:controller animated:YES];

电影播放正常,但顶部有一些MPMoviePlayerViewController没有使用的空间。

以下是显示问题的屏幕截图:https://www.dropbox.com/s/1dje2ar6ynk6855/IMG_2447.PNG

(我已将testController视图的背景设为黄色)

这部电影如何全屏播放?

2 个答案:

答案 0 :(得分:0)

也许尝试这样的事情:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];
    self.view.center = CGPointMake(self.view.center.x, self.view.center.y-100);
    [UIView commitAnimations];

如果不起作用,请尝试不使用模态视图控制器。

答案 1 :(得分:0)

尝试以另一种模式呈现视频,例如:

我没有测试此代码,但我认为它可以解决您的问题,因为您提出的问题可能是因为之前的模式。

NSURL *movieURL = [NSURL URLWithString:@"http://stream.qtv.apple.com/events/jan/1201oihbafvpihboijhpihbasdouhbasv/12pibasvpqihbsdfvihbasdv01_iphone_vod_ref.mov"];

self.mpc = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
NSLog(@"self mpc: %@", self.mpc);
[[NSNotificationCenter defaultCenter] addObserver:self  
                                         selector:@selector(moviePlayBackDidFinish:)  
                                             name:MPMoviePlayerPlaybackDidFinishNotification  
                                           object:self.mpc ];
self.mpc.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
self.mpc.moviePlayer.shouldAutoplay = YES; 
self.mpc.view.frame = self.view.frame;

[self presentModalViewController:self.mpc animated:NO];
self.mpc.moviePlayer.fullscreen = YES;
[self.mpc.moviePlayer play];