pablasso pablasso - 1 year ago 255
iOS Question

AVPlayer streaming progress

I'm successfully using

to stream audio from a server and what I want to do now is to show a custom
who shows the progress of the buffering.

Something like this:

enter image description here

there doesn't seem to be a way to get the total download size or the current downloaded amount for the audio file, only the current playing time and total play time.

There's any workarounds for this?

Answer Source

I am just working on this, and so far have the following:

- (NSTimeInterval) availableDuration;
  NSArray *loadedTimeRanges = [[self.player currentItem] loadedTimeRanges];
  CMTimeRange timeRange = [[loadedTimeRanges objectAtIndex:0] CMTimeRangeValue];
  Float64 startSeconds = CMTimeGetSeconds(timeRange.start);
  Float64 durationSeconds = CMTimeGetSeconds(timeRange.duration);
  NSTimeInterval result = startSeconds + durationSeconds;
  return result;