可以在全屏模式下在MPMoviePlayerController上显示UIActivityIndi​​cator吗?

Jor*_*gel 6 iphone mpmovieplayercontroller

在iphone应用程序中,我创建了一个MPMoviePlayerController并指示它开始以全屏模式播放视频(我认为除了iPhone上的F/S模式之外没有任何选项,就像你可以在ipad上一样).

一旦全屏播放器出现,整个屏幕都是黑色的,有时几秒钟内没有可见的控件(设置为MPMovieControlStyleDefault).

在一秒钟或三秒后,控件出现并显示视频的第一帧,然后视频开始缓冲并正确显示自动播放.

  1. 如何在全屏播放器上显示UIActivityIndi​​cator?我正在显示sharedApplication网络活动指示器,但我想显示带有"正在加载..."标签的完整尺寸指示器.

我已经尝试将它添加为电影播放器​​视图的子视图,即电影播放器​​的背景视图,作为电影播放器​​视图的超级视图的子视图(我当然没想到它会工作).我认为这里的关键是F/S电影播放器​​视图与不在F/S模式下的电影播放器​​视图不同.是?有没有办法访问全屏视图?

2.如果玩家以全屏模式启动,应该能够更快地看到控件(使用DONE按钮)吗?当全屏电影播放器​​启动时,只有黑屏会有相当长的延迟,所以如果用户变得不耐烦,用户就无法点击完成按钮(因此唯一的其他选择是退出应用程序 - 更愿意提供选项如果他们想要取消播放.

提前致谢!

Kri*_*kel 7

如果您还没有这样做,请注册MPMoviePlayerLoadStateDidChangeNotification通知(http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/c/data/MPMoviePlayerLoadStateDidChangeNotification)并在呈现电影播放器​​之前等待MPMoviePlayerController的loadState更改为MPMovieLoadStatePlayable.

这样,您可以在自己的视图中显示活动指示器,直到电影准备好播放.(请务必为用户提供取消等待电影的方法.)

从理论上讲,你应该能够在MPMovewPlayerController的视图中添加一个活动指示器,但我从来没有尝试过这种方法,听起来它不适合你.

另一种选择是在现有活动指标下添加MPMoviePlayer的视图.我成功地尝试了这个.

[moviePlayer setContentURL:trailer.downloadLink];
moviePlayer.fullscreen = YES;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer prepareToPlay];

[self.navigationController.view addSubview:self.activityIndicator];
self.activityIndicator.center = self.navigationController.view.center;
[self.activityIndicator startAnimating];

moviePlayer.view.frame = self.navigationController.view.bounds;
[self.navigationController.view insertSubview:moviePlayer.view belowSubview:self.activityIndicator];
Run Code Online (Sandbox Code Playgroud)

这是我的通知处理程序.

#pragma mark MPMoviePlayerController notifications

- (void)moviePlayerLoadStateChanged:(NSNotification *)notif
{
    NSLog(@"loadState: %d", moviePlayer.loadState);
    if (moviePlayer.loadState & MPMovieLoadStateStalled) {
        [self.activityIndicator startAnimating];
        [moviePlayer pause];
    } else if (moviePlayer.loadState & MPMovieLoadStatePlaythroughOK) {
        [self.activityIndicator stopAnimating];
        [moviePlayer play];

    }
}

- (void)moviePlayerPlaybackFinished:(NSNotification *)notif
{
    [moviePlayer.view removeFromSuperview];
    [self.activityIndicator stopAnimating];
}
Run Code Online (Sandbox Code Playgroud)