I'm using AVPlayer
to play audio from remote server.
I want to display a progress bar showing the buffering progress and the "time played" progress, like the MPMoviePlayerController
does when you play a movie.
Does the AVPlayer
has any UI component that display this info? If not, how can I get this info (buffering state)?
Thanks
No, there's no UI component for AVPlayer.
You should observer AVPlayerItem.loadedTimeRanges
[yourPlayerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
then using KVO to watch
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if(object == player.currentItem && [keyPath isEqualToString:@"loadedTimeRanges"]){
NSArray *timeRanges = (NSArray*)[change objectForKey:NSKeyValueChangeNewKey];
if (timeRanges && [timeRanges count]) {
CMTimeRange timerange=[[timeRanges objectAtIndex:0]CMTimeRangeValue];
}
}
}
timerange.duration
is what you expect for.
And you have to draw buffer progress manually.
Refs here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With