I want to play mp3 files from my Server, i do the following:
NSURL *url = [NSURL URLWithString:item.audioUrl];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.player addObserver:self forKeyPath:@"status" options:0 context:nil];
self.hud = [[MBProgressHUD alloc]initWithFrame:CGRectMake(150, 5, 50, 50)];
self.hud.mode = MBProgressHUDModeIndeterminate;
[self.hud show:YES];
[self.containerView addSubview:self.hud];
Here is my observeValueForKeyPath:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self.player && [keyPath isEqualToString:@"status"])
{
if (self.player.status == AVPlayerStatusReadyToPlay)
{
[self.hud hide:YES];
[self.player play];
.
.
.
Now the Problem is that even when the Status of the AVPlayer have changed to "readyToPlay" it still takes about 2-3 seconds before it starts playing and of course my loading Spinner gets hidden before the music starts....any Ideas?