我有一个 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];
}
有帮助吗?

解决方案

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

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

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

然后在你的“videoButton1”中你可以将View的alpha设置为0

viewForMovie.alpha = 0;

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top