加载新视频时隐藏MPMoviePlayerController

时间:2010-12-03 17:42:50

标签: iphone ipad hide mpmovieplayercontroller uiactivityindicatorview

我有一个iPad应用程序,左侧有4个按钮,对应4个不同的视频剪辑。当用户点击他们想要查看的视频时,它会显示在右侧。我希望它似乎正在加载(好像它是通过互联网流式传输)。我将UIActivityIndi​​cator添加到黑色视频帧的中心,并有一个暂停3秒的线程。但是,包含上一个视频的播放器不会消失。它只会冻结上一个视频的最后一帧3秒钟(隐藏活动指示器),然后出现新视频。

有关如何暂时隐藏玩家的任何想法?谢谢你的帮助。这是我的代码:

-(IBAction) videoButton1{
   [player stop];
   [player release];

   [self.activityIndicator startAnimating];

   NSString *url = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mov"];
   [self setupVideoPlayer:url];
}

-(void) setupVideoPlayer: (NSString *) url{
   player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url)];
   player.view.frame = CGRectMake(487, 205, 478, 320);

   [self.view addSubview:player.view];

   [NSThread sleepForTimeInterval:3.0];
   self.activityIndicator stopAnimating];

   [player play];
}

1 个答案:

答案 0 :(得分:2)

您可以将播放器的帧设置为您可以在IB中进行或以编程方式制作的视图,而不是每次都进行CGRectMake。

  

self.player.view.frame =   self.viewForMovie.bounds;

     

self.player.view.autoresizingMask =   UIViewAutoresizingFlexibleWidth |   UIViewAutoresizingFlexibleHeight;

然后在“videoButton1”中,您可以将视图的alpha设置为0

  

viewForMovie.alpha = 0;

在“setupVideoPlayer”中,您可以将alpha更改回1.

相关问题