iPhone MediaPlayer - 全屏?

时间:2011-07-28 17:06:15

标签: iphone media-player mpmovieplayercontroller

我已经浏览了一些其他示例,但我无法在viewController中获取全屏加载视频。

我可以加载它......但不能全屏启动。

代码如下。谢谢!

-(void)viewWillAppear:(BOOL)animated {     
    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"m4v"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];

    [moviePlayerController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    [moviePlayerController play];
    }


- (void) movieFinishedCallback:(NSNotification*) aNotification {
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:player];    
    [player autorelease];
    }

编辑:全屏固定...我只需添加:moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

现在它在我的状态栏中添加了一个奇怪的图像..参见附图。

enter image description here

1 个答案:

答案 0 :(得分:0)

我不知道fullscreen的含义是什么意思,但我通常会看到这一行

  [moviePlayerController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

bounds作为参数编写,如下所示

[moviePlayerController.view setFrame:self.bounds];

 [moviePlayerController.view setFrame:self.view.bounds];

取决于对象self的类型。