iphone - UI ActivityIndi​​cator 能否以全屏模式显示在 MPMoviePlayerController 上?

标签 iphone mpmovieplayercontroller

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

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

一秒或三秒后,出现控件和视频的第一帧,然后视频开始缓冲并正确自动播放。

  1. 如何在全屏播放器顶部显示 UIActivityIndi​​cator?我正在显示共享应用程序网络事件指示器,但我想显示带有“正在加载...”标签的全尺寸指示器。

我尝试将其添加为电影播放器​​ View 的 subview 、电影播放器​​的背景 View 、电影播放器​​ View 的 super View 的 subview (我当然没想到这会起作用)。我认为这里的关键是 F/S 电影播放器​​ View 与不处于 F/S 模式时电影播放器​​的 View 不同。是的?有没有办法访问全屏 View ?

2.对于以全屏模式启动的玩家,控件是否应该更快可见(使用“完成”按钮)?当全屏电影播放器​​启动时,会有相当长的延迟,除了黑屏之外什么也没有,因此用户如果不耐烦就无法点击“完成”按钮(因此唯一的其他选择是退出应用程序 - 更愿意提供一个选项如果他们愿意,可以取消播放。

提前致谢!

最佳答案

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

这样,您就可以在自己的 View 上显示事件指示器,直到电影准备好播放为止。 (请确保为用户提供取消等待电影的方法。)

理论上,您应该能够向 MPMovewPlayerController 的 View 添加事件指示器,但我从未尝试过这种方法,而且听起来它不适合您。

另一个选项是在现有事件指示器下方添加 MPMoviePlayer 的 View 。我刚刚尝试过,成功了。

[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];

这是我的通知处理程序。

#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];
}

关于iphone - UI ActivityIndi​​cator 能否以全屏模式显示在 MPMoviePlayerController 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3799299/

相关文章:

iphone - 核心数据 : The fetched object at index x has an out of order section name 'xxxxxx. 对象必须按节名排序

ios - 如何使用从套接字连接加载的数据初始化视频对象-iOS

iPhone MPMoviePlayerViewController : extract total duration

ios - MPMoviePlayerController View 无法识别触摸

iphone - iOS4 MPMoviePlayerController 嵌入

iPhone MPMoviePlayerController : Hiding the status bar

ios/iphone sdk 表单管理最佳实践

iphone - 找不到尺寸正确的图标 120 x 120 的图像

ios - 背景模糊效果?

ios - 如何对齐 View 和 subview 中心 Objective-C