在启动屏幕上无需控制即可全屏播放视频

时间:2012-09-16 11:40:45

标签: ipad video fullscreen playback

我正在创建一个iPad应用程序,我想在应用程序加载数据时在启动屏幕上无控制地播放视频全屏,我搜索并找到一些关于MPPlayerViewController的文章,我用它但我有一些问题如下:

  • 我使用下面的代码播放视频:
NSString *moviePath = [ [[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"StartupVideo.mp4"];
    moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
    moviePlayerViewController.view.frame = self.view.bounds;

    [self.view addSubview:moviePlayerViewController.view];
    [self.view sendSubviewToBack:moviePlayerViewController.view];

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

    MPMoviePlayerController *player = [moviePlayerViewController moviePlayer];
    player.fullscreen = YES;
    player.movieSourceType = MPMovieSourceTypeFile;
    player.initialPlaybackTime = -1.0;
    [player play];

一切似乎都没错,但视频没有加载,我只看到黑屏。

  • 如何隐藏MPVideoPlayerView中的控件?

1 个答案:

答案 0 :(得分:0)

而不是     [NSURL URLWithString:moviePath]

使用

[NSURL fileURLWithString:moviePath]

让我这么多次.. :)