0

我有一个水平滚动视图,例如 Springboard,每个页面上有 16 个按钮。当您单击一个按钮时,我只想看到播放视频的 MPMoviePlayerController 而没有其他内容,就像您在视频应用程序中观看电影一样。因此,我有以下代码:

- (void)button: (id) sender {
    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"MOV"];
    NSURL *videoURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

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

    moviePlayerController.fullscreen = YES;

    [self.view addSubview:moviePlayerController.view];
    [moviePlayerController play];
}

- (void)moviePlaybackComplete:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:moviePlayerController];

    [moviePlayerController.view removeFromSuperview];
    [moviePlayerController release];
}

不幸的是,我只能听到声音并且没有视频显示。有人可以帮我吗?

更新:我发现你必须制作一个框架。我使用了以下代码:

[moviePlayerController.view setFrame:CGRectMake(0, 0, 768, 1004)];

但它不是这样全屏的。即使我已将全屏属性设置为 YES。我可以看到,因为视图顶部没有视频控件,但视图底部没有。

4

1 回答 1

0

我找到了解决方案。您应该使用以下代码:

NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"MOV"];
NSURL *videoURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerViewController *playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

[self presentModalViewController:playerView animated:YES];
于 2012-08-30T19:54:57.570 回答