MPMoviePlayerController全屏不起作用

时间:2012-08-15 18:01:13

标签: objective-c ios mpmovieplayercontroller fullscreen

我的代码正常播放视频,但不是全屏播放。

-----------  
|_______  |  
|XXXXXXX| |  
|XXXXXXX| |    
-----------

它的大小大约是X存档区域的大小 我在ipad2上运行它。

 NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"movie.mp4" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:videoPlayer];
    [self.view addSubview:videoPlayer.view];
    [videoPlayer setFullscreen:YES];
    videoPlayer.view.frame = [[UIScreen mainScreen] bounds];  
    [videoPlayer play];    
    [super viewDidLoad];    

1 个答案:

答案 0 :(得分:2)

MPMoviePlayerController的边框设置为1024x768。

videoPlayer.view.frame = CGRectMake(0,0,1024,768); //748 if you have status bar.

希望这就是你要找的东西。 *编辑:尝试这种方式,这是我使用的那个。

UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:tempView];

playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"www.orangebob.com/files/movie.mp4"]];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(movieFinishedCallback:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:[playerViewController moviePlayer]];

playerViewController.view.frame = CGRectMake(0, 0, 1024, 768);
[tempView addSubview:playerViewController.view]; //This *fixes* it, but it's kinda dirty.



MPMoviePlayerController *player = [playerViewController moviePlayer];

[player play];