3
A
回答
9
这会将活动视图添加到视图的中心。在你处理播放按钮的“IBAction”中添加此代码。
UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
[self.view userInteractionEnabled:NO]; //to avoid touch events when activity is on
并停止活动的指标使用
[activityView stopAnimating];
[activityView removeFromSuperview];
[self.view userInteractionEnabled:YES];
这是this link about AV Foundation。和this answer - >
使用志愿,有可能被通知的玩家状态的变化:
player = [AVPlayer playerWithURL:fileURL];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
在PLAY按钮的事件中添加代码,以启动UIActivityIndicator
这种方法将在状态发生变化时调用:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:@"status"]) {
if (player.status == AVPlayerStatusReadyToPlay) {
//DISABLE THE UIACTIVITY INDICATOR HERE
} else if (player.status == AVPlayerStatusFailed) {
// something went wrong. player.error should contain some information
}
}
}
+0
嗨, 解决了,这就是我一直在寻找的。谢谢。 – 2013-04-27 19:47:47
你想澄清如何添加e活动指标?在播放按钮之前和播放器开始之前,您是否获得回调? – Amit 2013-04-25 05:30:05
你有没有试过使用AVPlayerViewController?它已经包含指示所有加载进度+ AVPlayer的活动指示符。 – 2016-09-06 15:06:23