我为收音机开发了一个应用程序,它正在工作。
我想放置一个活动指示器视图,以便当您触摸播放时它会启动活动指示器视图,而当音频开始时,活动指示器会停止。
我为收音机开发了一个应用程序,它正在工作。
我想放置一个活动指示器视图,以便当您触摸播放时它会启动活动指示器视图,而当音频开始时,活动指示器会停止。
这会将活动视图添加到视图的中心。将此代码添加到您处理播放按钮的“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];
这是来自这个关于 AV Foundation 的链接。这个答案- >
使用 KVO,可以通知播放器状态的变化:
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
}
}
}