可以在全屏模式下在MPMoviePlayerController上显示UIActivityIndi​​cator吗? [英] Can a UIActivityIndicator be displayed over a MPMoviePlayerController in full screen mode?

查看:149
本文介绍了可以在全屏模式下在MPMoviePlayerController上显示UIActivityIndi​​cator吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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



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


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

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



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



提前致谢!

解决方案

如果您还没有这样做,请注册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.activityIndi​​cator];
self.activityIndi​​cator.center = self.navigationController.view.center;
[self.activityIndi​​cator startAnimating];

moviePlayer.view.frame = self.navigationController.view.bounds;
[self.navigationController.view insertSubview:moviePlayer.view belowSubview:self.activityIndi​​cator];

以下是我的通知处理程序。

  #pragma mark MPMoviePlayerController notifications 

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

}
}

- (无效)moviePlayerPlaybackFinished:(NSNotification *)notif
{
[moviePlayer.view removeFromSuperview];
[self.activityIndi​​cator stopAnimating];
}


In an iphone app, I create an MPMoviePlayerController and instruct it to start playing video in full screen mode (I don't think there is any option for anything but F/S mode on iPhone like you can on ipad).

Once the full screen player comes up, the entire screen is black and there are no controls visible (set to MPMovieControlStyleDefault) for several seconds sometimes.

After a second or three, the controls appear and the first frame of the video, then the video begins to buffer and autoplays correctly.

  1. How can I display a UIActivityIndicator on top of the full screen player? I am displaying the sharedApplication network activity indicator, but I want to show a full size indicator with a "Loading..." label.

I've tried adding it as a subview of the movie player's view, the movie player's background view, as a subview of the movieplayer view's superview (I didn't expect that to work of course). I think the key here is that the F/S movie player view is not the same as the movieplayer's view when not in F/S mode. Yes? Is there a way to access the full screen view?

2.Should the controls be visible (with the DONE button) sooner for a player started in full screen mode? There is a fairly long delay with nothing but black screen when the full screen movie player starts, so the user cant tap the Done button if they become impatient (therefore the only other choice will be exit the app - would prefer to provide an option to cancel the playback if they want.

Thanks in advance!

解决方案

If you're not already doing so, register for the MPMoviePlayerLoadStateDidChangeNotification notification (http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/c/data/MPMoviePlayerLoadStateDidChangeNotification) and wait for the MPMoviePlayerController's loadState to change to MPMovieLoadStatePlayable before presenting the movie player.

That way, you can present the activity indicator over your own view until the movie is ready to play. (Be sure to include a way for the user to cancel waiting for the movie.)

In theory, you should be able to add an activity indicator to the MPMovewPlayerController's view, but I've never tried that approach and it sounds like it isn't working for you.

Another option is to add the MPMoviePlayer's view below an existing activity indicator. I successfully just tried this.

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

Here are my notification handlers.

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

这篇关于可以在全屏模式下在MPMoviePlayerController上显示UIActivityIndi​​cator吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆