Reputation: 1031
I am using the AVPlayer to play a live stream from the Internet, and need to show than the player is buffering :
I am using an NStimer :
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(buffering) userInfo:nil repeats:YES];
-(void)buffering {
if(radiosound.rate == 1.0)
[activityIndicator stopAnimating];
else
[activityIndicator startAnimating];
}
For sure rate property is not working properly to show ! Is it an other statement to know if the AVPlayer is buffering ?
Upvotes: 0
Views: 1469
Reputation: 1527
Use the NSURLConnection class in conjunction with the NSURLConnectionDataDelegate protocol.
Upvotes: 0
Reputation: 4036
You need to look at setting up key-value observers for the loaded times, and use that to figure out if you are waiting for data at the current play point.
Observers are setup using addObserver:self forKeyPath: options: context:
method on AVPlayerItem
and then in the observeValueForKeyPath: ofObject: change: context:
callback you can figure out what times have been loaded compared with where in the item the player is playing.
You won't see the rate
variable drop to zero when buffering, as this is the desired playback rate, not the actual rate being achieved.
Upvotes: 3